Draw Efficiency/Memory Management with Tilesheets

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.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #5878

    Raudius
    Participant

    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

    #5884

    Mark Sibly
    Keymaster

    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.

    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:

    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.

    #5885

    arpie
    Participant

    Deleted.  Mark’s answer was much better 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.