Reputation: 3196
I'm making a health bar for a battle scene in a game with cocos2d. If I was doing this in web design the most optimized way to do it would be a 1px by (height) image of the color I wanted, repeated horizontally as far as I needed it to be. Is this the case with iPhone's as well?
Would it be better, performance-wise, to have 1 small sprite and repeat it multiple times until it's the width I need or would it be better to just have the image of the bar I needed and then scale it down as the monster loses health?
Upvotes: 1
Views: 214
Reputation: 1377
Start with the 1px by height image. Set the scale x property to scale it appropriately to correspond to the health. I'm pretty certain you can scale a sprite to whatever you want and will still use the same amount of memory (don't quote me on that).
Despite this, one full sized sprite isn't going to affect the performance a whole lot, so if you want to use a full image (to make it more detailed than just a box), then it's probably fine.
If you want to use a full sized image and are still worried about performance, put it into a texture atlas (sprite sheet) with all of your other sprites (because you are using texture atlases (sprite sheets), right? ;) ) and render it with a CCBatchNode.
Hope this helps.
Upvotes: 1