Multiple identical sprites. Efficient memory usage?

32 views
Skip to first unread message

Thomas Bernard

unread,
Sep 14, 2015, 11:55:20 AM9/14/15
to HaxeFlixel
Hi

  I have a game whith some level rating (between 0 and 10) rendered as stars (0 to 5 stars with half colored stars for unpair ratings).
My question is how to efficiently render the 10 possible rating sprites with as less memory and computation time as possible.
I see 3 possible options:

1 - create 10 pictures of my 5 stars, one for each possible rating, and load the one matching my current rating
2 - create 3 single star pictures: one of a complete colored star, one of an half colored star and one of an empty (black) star and generate an flxspritegroup that concatenate 5 of this pictures sprite to render a 5 stars sprite matching my rating
3 - have a black picture of 5 stars and use it as a mask with the Bitmapdata.copyChanel() function over a partially colored bitmapdata of same size to generate a picture of my 5 stars

I don't know which solution is preferable.
If I load an image with FlxSprite.loadGraphic(asset_path), by default does it uses some cache? Meaning if I load the same picture multiple time, would it have to retrieve it from the file system or would it be only for the first time and then directly served from the cache? In this case, I assume solution 2 would be the more efficient as it requiere only 3 small stars pictures and having 5 flxsprite into a flxspritegroup instead of one big flxsprite of the same size probably do not have any significant impact on performances?

Any opinion and possible other option is welcome.
 

Seb Jones

unread,
Sep 14, 2015, 3:01:44 PM9/14/15
to HaxeFlixel
For something like this, I wouldn't even be too concerned about memory/performance, since it isn't an intensive aspect of the game. Just do whatever seems most straightforward to implement. That's my opinion, anyway :)
Reply all
Reply to author
Forward
0 new messages