0

我一直在FPS延迟。我环顾四周,人们说要使用

[self schedule:@selector(gameLoop:) interval: 1/60.0f];

当我使用它时,我会遇到不稳定的延迟。但是当我使用

[self schedule:@selector(gameLoop:)];

它平滑了很多。这是我的运动代码片段。

- (void)gameLoop :(ccTime)dt
{
    [self manageCannon:dt];
    [self manageBullets:dt];
    [self manageEnemies:dt];
    [self manageAllies:dt];
}
- (void) manageEnemies :(ccTime)dt
{
    enemyClass *tempEnemy;
    for(int i = 0; i < [enemies count]; i++)
    {
        tempEnemy = [enemyClass new];
        tempEnemy = [enemies objectAtIndex:i];

        tempEnemy.position = ccp(tempEnemy.position.x-tempEnemy.speed*dt,tempEnemy.position.y);

        if((tempEnemy.position.x - tempEnemy.range) < [wall getwally])
        {
            tempEnemy.speed = 0;
        }
        if(tempEnemy.health < 1)
        {
            tempEnemy.alive = false;
        }

        if(tempEnemy.alive == false)
        {
            [enemies removeObjectAtIndex:i];
            [tempEnemy removeFromParentAndCleanup:true];
        }
    }
}

我总是尝试从头开始编写自己的代码,所以如果你能帮助我解决我正在做的其他事情,那对我来说是不正确的。

4

1 回答 1

0

It's hard to say what is slowing down your app from the information given. As LearnCocos2D suggested, you can use Instruments to figure out where the slow stuff is. Or if you want to get very granular analysis, you can always use the following macros in your code:

#define TIC start = [NSDate date]
#define TOC -[start timeIntervalSinceNow]
#define TOCP NSLog(@"TIME: %f", TOC)

Before using, be sure to declare NSDate *start in scope of use. Then just put a series of TIC/TOC or TIC/TOCP pairs in your code to print out times your code is taking in different places. You can very quickly find the bottlenecks this way.

于 2013-08-24T07:23:24.810 回答