I'm working in a Cocos2D + Chipmunk game and I'm experiencing some annoying performance problems in cases where maybe there shouldn't be... The game has some static chipmunk squares (around 150-200, but which didn't even move: they're just like walls or floors) and some moving chipmunk circles (around 10-20). The game starts with 60 FPS as expected, but as the moving circles begin to appear, the FPS count begin to fall and reaches around 40 or 30... It is possible that the fact that exists around 20 moving entities is enough to drop the framerate as I'm experiencing, or maybe it has something to do with my internal code?
Here is an example on how the game creates each static "wall-floor" blocks:
Code: Select all
CCNode *parent = [self getChildByTag:kTag];
CGRect spriteRect = CGRectMake(offset.x, offset.y, size.width, size.height);
PhysicsSprite *sprite = [PhysicsSprite spriteWithTexture:text rect:spriteRect];
sprite.position = pos;
int num = 4;
cpVect verts[] = {
cpv(-bSize.x/2.0f,-bSize.y/2.0f),
cpv(-bSize.x/2.0f, bSize.y/2.0f),
cpv( bSize.x/2.0f, bSize.y/2.0f),
cpv( bSize.x/2.0f,-bSize.y/2.0f),
};
cpBody *body = cpBodyNew(INFINITY, INFINITY);
cpBodySetPos( body, pos);
cpShape* shape = cpPolyShapeNew(body, num, verts, CGPointZero);
cpShapeSetElasticity( shape, 0.3f );
cpShapeSetFriction( shape, 0.5f );
cpShapeSetCollisionType(shape, kCollisionTypeNormal);
shape->data = sprite;
[parent addChild: sprite];
cpSpaceAddShape(space_, shape);
[sprite setPhysicsBody:body];
Code: Select all
CCNode *parent = [self getChildByTag:kTag];
CGRect spriteRect = CGRectMake(offset.x, offset.y, size.width, size.height);
PhysicsSprite *sprite = [PhysicsSprite spriteWithTexture:text rect:spriteRect];
sprite.position = pos;
int num = 4;
cpVect verts[] = {
cpv(-bSize.x/2.0f,-bSize.y/2.0f),
cpv(-bSize.x/2.0f, bSize.y/2.0f),
cpv( bSize.x/2.0f, bSize.y/2.0f),
cpv( bSize.x/2.0f,-bSize.y/2.0f),
};
cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, CGPointZero));
cpBodySetPos( body, pos );
cpShape* shape = cpCircleShapeNew(body, bSize.x/2.0f, CGPointZero);
cpShapeSetElasticity( shape, 0.6f );
cpShapeSetFriction( shape, 0.5f );
cpShapeSetCollisionType(shape, kCollisionTypeBestiola);
cpShapeSetGroup(shape, kCollisionGroupNoCollision);
[parent addChild: sprite];
cpSpaceAddBody(space_, body);
cpSpaceAddShape(space_, shape);
[sprite setPhysicsBody:body];
Thanks in advance for your time and effort!