我正在做一个游戏,我只有一个最后的问题。当游戏创建一个敌人时,FPS会减慢到40或20。取决于它是创建1个还是2个敌人。
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 3; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"laser_%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.12f];
CCSprite *laser = [CCSprite spriteWithSpriteFrameName:@"laser_1.png"];
int tempY = (arc4random() % ((int)(300 - laser.boundingBox.size.height))) + laser.boundingBox.size.height;
float tempRot = (arc4random() % 30) + 1;
int sign = (arc4random() % 2) - 1;
if (sign < 0) {
tempRot *= -1;
}
laser.tag = 2;
laser.position = ccp(650, tempY);
laser.rotation = CC_RADIANS_TO_DEGREES(tempRot);
CCAction *walkAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:YES]];
[laser runAction:walkAction];
[spriteSheet addChild:laser];
b2BodyDef spriteBodyDef;
spriteBodyDef.type = b2_dynamicBody;
spriteBodyDef.position.Set(laser.position.x/PTM_RATIO,
laser.position.y/PTM_RATIO);
spriteBodyDef.userData = laser;
b2Body *spriteBody = world->CreateBody(&spriteBodyDef);
[[GB2ShapeCache sharedShapeCache] addShapesWithFile:@"laserBody.plist"];
[[GB2ShapeCache sharedShapeCache] addFixturesToBody:spriteBody forShapeName:@"laser_1"];
[laser setAnchorPoint:[[GB2ShapeCache sharedShapeCache] anchorPointForShape:@"laser_1"]];
//pixeles recoridos/velocidad del move actual
float timeAnim = 800/(60*move);
[laser runAction:[CCSequence actions:
[CCMoveBy actionWithDuration:timeAnim position:ccp(-800, 0)],
[CCCallFuncN actionWithTarget:self selector:@selector(obstaclesDone:)],
nil]]; 我正在使用Physic Editor来创建形状。在它创建之后。这个游戏在60帧/秒的速度下运行良好。但仅限于iPhone。在我的iMac中工作得很好。
我可以做些什么来创建它而不丢失fps。也许是在第二个处理器里。或者是另一个线程?
谢谢:)
发布于 2011-12-11 10:08:53
您使用的纹理的大小和质量是什么?这可能是因为创建精灵实例需要太多的内存,使得很难保持高帧率不断改变这些精灵的位置。您还可以尝试使用Instruments进行性能分析,以查看是什么占用了您的处理器周期。
https://stackoverflow.com/questions/8461226
复制相似问题