首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >制造敌人,减慢游戏Cocos2d

制造敌人,减慢游戏Cocos2d
EN

Stack Overflow用户
提问于 2011-12-11 09:17:24
回答 1查看 403关注 0票数 0

我正在做一个游戏,我只有一个最后的问题。当游戏创建一个敌人时,FPS会减慢到40或20。取决于它是创建1个还是2个敌人。

代码语言:javascript
复制
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。也许是在第二个处理器里。或者是另一个线程?

谢谢:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-11 10:08:53

您使用的纹理的大小和质量是什么?这可能是因为创建精灵实例需要太多的内存,使得很难保持高帧率不断改变这些精灵的位置。您还可以尝试使用Instruments进行性能分析,以查看是什么占用了您的处理器周期。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8461226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档