【发布时间】:2011-12-11 01:17:24
【问题描述】:
我正在做一个游戏,我只遇到了 1 个最终问题。当游戏创建一个敌人时,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]];
我正在使用物理编辑器来创建形状。创建后。游戏在 60 fps 下运行良好。但仅限于 iPhone。在我的 iMac 上完美运行。
如何在不丢失 fps 的情况下创建它。也许在第二个处理器中。还是其他线程?
谢谢:)
【问题讨论】:
标签: iphone cocos2d-iphone