Reputation: 4049
I wrote a simple game with Cocos2D where I have an animated sprite walking around a plain green field.
The walking sprite is 64x64px, the joystick comes from the Sneakyjoystick class, and the green field is composed of a 5-6 32x32 pixels made into a tilemap using Tiled. Using Tiled, I created a 50 x 50 tile map.
I'm getting 20-30 FPS and I'm not sure why. I decreased the tilemap size to 10x10 tiles and it shot up to 50-60 FPS. I don't know what to do?
Edit: I've added the initialization block for the gameplay layer. I'm testing on the simulator.
-(id) init
{
if( (self=[super init] ))
{
self.tileMap = [CCTMXTiledMap tiledMapWithTMXFile:@"TileMap.tmx"];
self.background = [_tileMap layerNamed:@"Background"];
self.meta = [_tileMap layerNamed:@"Meta"];
self.topLayer = [_tileMap layerNamed:@"TopLayer"];
_topLayer.visible = YES;
_background.visible = YES;
_meta.visible = YES;
[self addChild:_tileMap z:-1];
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@"male_walkcycle.plist"];
sceneSpriteBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"male_walkcycle.png"];
[self addChild:sceneSpriteBatchNode z:0];
CCTMXObjectGroup *objects = [_tileMap objectGroupNamed:@"Objects"];
NSAssert(objects != nil, @"'Objects' object group not found");
NSMutableDictionary *spawnPoint = [objects objectNamed:@"SpawnPoint"];
NSAssert(spawnPoint != nil, @"SpawnPoint object not found");
int x = [[spawnPoint valueForKey:@"x"] intValue];
int y = [[spawnPoint valueForKey:@"y"] intValue];
Caster *casterPlayer = [[[Caster alloc] init] initWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"male_walkcycle_19.png"]];
casterPlayer.position = ccp(x, y);
casterPlayer.joystick = nil;
[sceneSpriteBatchNode addChild:casterPlayer z:1000 tag:kCasterTagValue];
[casterPlayer release];
CCSprite *sprite = [CCSprite node];
CGSize size = CGSizeMake(50,50);
GLubyte *buffer = malloc(sizeof(GLubyte)*4);
for (int i=0;i<4;i++) {buffer[i]=255;}
CCTexture2D *tex = [[CCTexture2D alloc] initWithData:buffer pixelFormat:kCCTexture2DPixelFormat_RGB5A1 pixelsWide:1 pixelsHigh:1 contentSize:size];
[sprite setTexture:tex];
[sprite setTextureRect:CGRectMake(0, 0, size.width, size.height)];
free(buffer);
sprite.position = ccp(x, y);
sprite.visible = NO;
[self addChild:sprite z:5 tag:debugBoxTagValue];
[self setViewpointCenter:casterPlayer.position];
[self scheduleUpdate];
}
return self;
}
Upvotes: 1
Views: 1367
Reputation: 64477
I'm testing on the simulator.
I can't believe how often I need to repeat this:
Ignore the Simulator!
The Simulator is not an actual iOS device. It runs on your Mac. It has more memory and CPU power available. At the same time its rendering performance is severely limited because it's not hardware accelerated rendering, it's a software renderer.
Even the fastest 2012 iMac can't run scenes at 60 fps on the iPad or iPhone Retina Simulator. On the iPad Retina Simulator you'll be lucky to get 20 fps.
Moreover, developers are the only people ever to run their Apps on the Simulator. Your users, not even your testers, will be using the Simulator to run your app. They'll be using an actual device.
Any time spent optimizing performance on the Simulator is nothing but a complete waste of time. This generally applies to any issue that only occurs on the Simulator.
Test on a device! Every issue only observed on the iOS Simulator is moot, void, invalid, and utterly irrelevant, especially performance.
Upvotes: 7