I'm creating one of my first HTML5 games. It's a game sort of like Ministry of War/War of Legends. It's an isometric tile-based MMORTS game. Now, while I'm building the game, I'm trying to keep resource management and speed in mind; however, I've come across an issue.
I have a method called renderMap
that follows these steps
renderMap
loads the current map chunk. A map chunk is currently defined as 6x6 grid of tiles.renderMap
loops through each individual tile from ASCENDING X,Y to DESCENDING X,Y and draws that tile onto the isometric grid. While drawing the tile to the screen, it will also check if building is on that tile, and will draw that building on top of the tile.
Now, because renderMap
has to call drawImage
about 36 times for each individual tile that is a part of the chunk, it really begins to become a resource hog if the function were to be called every frame. So, I made renderMap
draw to the in-memory canvas, which is drawn to the main canvas every frame. So 36 calls of drawImage
is reduced to only 1 every frame.
And the only time I need to call renderMap
, is if the tiles or buildings update in anyway. For instance, if a new chunk is loaded and we need to load the new isometric map.
However, what if I want these buildings or tiles to have animations?
For example, I add a building called an oil well
to the game. If an oil well is on any of the tiles in the 6x6 chunk that is loaded on the player's client and displayed, it will force the game to have to call renderMap
so many more times, in order to render that single building's new image (because animation). So I end up rendering 35 extra tiles just in order to update that 1 building.
What can I do about this? Is just best to not include animations?
Here's what the game looks like, so this might be of help in regards to adding context to the problem:
(sorry the picture is cluttered ... I was doing a little testing)