About Monkey 2 › Forums › Monkey 2 Programming Help › Draw Efficiency/Memory Management with Tilesheets
This topic contains 2 replies, has 3 voices, and was last updated by
arpie
2 years, 4 months ago.
-
AuthorPosts
-
December 18, 2016 at 6:58 pm #5878
So I’ve been getting back into this monkey business and I’m going bananas trying figuring out if I’m doing things the right way.
I’ve just started my project and so far I’m loading each Tile from a TileSheet and then storing them in a grid (array) and then iterating through this array to render each Tile.
Question 1: I’m loading each Tile Image as a subimage from a tilesheet image. Is this more efficient than just drawing the corresponding subimage of the tilesheet image each Render cycle for each Tile.
Question 2: If answer to 1 is yes. How do I unload the tilesheet image from memory after I’m done loading each tile from it.
Question 3: Is there some way to perform “instanced rendering” (https://en.wikipedia.org/wiki/Geometry_instancing) to make rendering the Tiles more efficient?
Question 4: Does any of this matter? Is there sufficient overhead in order for me not to worry about performance? Or is it possible that if I dont, I’ll run into performance issues in the longrun?
Thanks,
Raudius
December 18, 2016 at 9:49 pm #5884I’m loading each Tile Image as a subimage from a tilesheet image. Is this more efficient than just drawing the corresponding subimage of the tilesheet image each Render cycle for each Tile.
The optimal way to handle atlases/tiles is to load the ‘atlas’ once using Image.Load, then create tiles using ‘New Image( atlas,x,y,w,h ) ‘ etc.
If answer to 1 is yes. How do I unload the tilesheet image from memory after I’m done loading each tile from it.
You want to leave the altas in memory – the basic idea is:
Monkey1234567atlas=Image.Load( "..." )tile0=New Image( atlas,0,0,16,16 )tile1=New Image( atlas,16,0,16,16 ) ...etc...play the game until atlas no longed needed...atlas.Discard() 'will discard tiles automatically.Basically, you only need to Discard() what you’ve .Load()ed. That’s the theory anyway…
Is there some way to perform “instanced rendering”
Not really, although it generally pays to try and eliminate ‘render state changes’ when drawing – this basically means ‘batching’ draw calls that use the same atlas and blend mode. If you’re drawing tiles from a single atlas using a single blend mode, there’s nothing to do here!
Does any of this matter?
Depends what you’re doing.
December 18, 2016 at 9:49 pm #5885Deleted. Mark’s answer was much better
-
AuthorPosts
You must be logged in to reply to this topic.