views:

721

answers:

2
+1  Q: 

Sprite backgrounds

I use cocos2d for iphone and in my game I'm using a sprite as static background image.

I've noticed that when removing code for adding the sprite the framerate goes from ~30fps to over 40fps. Is it any other way to show a static background that is less expensive? I'm not moving the background sprite at all.

To code right now:

background = [Sprite spriteWithFile:@"t1_5.jpg"];
[self addChild:background z:0];
background.position = ccp(240, 160);
A: 

Not an easy question, like every question that concerns Cocos2D performance. Large images always take CPU to render. You can only reduce it to make performance acceptable (stable 30 fps is a good result)

There are pretty good advices given by original developer.

From my own experience I prefer to use color filled background with small sprites over using solid image background. Repeating elements should also use single texture with different sprites.

Reducing texture quality to 16 bit can also help.

[Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA4444]; // add this line at the very beginning

I can be more specific on topic if you provide more info like attaching the background itself.

Stanislav
I think you gave good examples for optimizing there that can be useful for many others. And I guess that the anwer for my question is no. There is no magical way of defining a bitmap as a background that takes up almost no resources.
Mattias Akerman
A: 

I recommend converting all of your Sprites to AtlasSprite. That way you have an AtlasSpriteManager that loads the background file once, and when you need the sprites themselves it's just clipping the image. AtlasSprite is just generally faster than the legacy Sprite stuff.

Chris Garrett