I load a large tileset image in at the start of my program.
To draw the game world, I loop over a 2D array of tile IDs and based on that ID I cut out a 16x16 portion from the tileset and draw that as an image, using the 9 parameter overload of canvasContext.drawImage()
. This is nice since there is only a single Image
object needed.
However, I am wondering if it is better practice to, as a preprocessing step, seperate the tileset image into a bunch of different Image
objects for each tile, and then just draw those. My thinking is that this would potentially be faster by saving the work done each frame to crop out portions from the larger complete tileset image.
I know the ideal approach would probably be to preprocess the tile ID array into one large image containing every tile that makes up the world, and then to just draw that. This would work for me right now, however, I may decide to change the map at runtime and then I assume the overhead of recalculating the entire 'world image' during gameplay would be too large.
Given this potential requirement, which approach would be better practice?