当我“滚动”时,为什么这款iphone应用程序会滞后?

时间:2010-07-13 05:24:42

标签: iphone objective-c uiimageview runtime-error lag

我正在开发像游戏一样的“涂鸦跳转”,我一次在屏幕上有5个平台。有两个背景UIImageViews。我有“scrollUp”功能,只要播放器位于屏幕的前3/4位,就会调用该功能。当背景在视野中时,游戏变慢并且滞后,当背景不在视野中(已经被甩掉)时,游戏运行平稳而精细。我尝试禁用使它们移动的实际代码并且它仍然滞后,背景图像都是我在photoshop中创建的png,并且每个都在单独的UIImageView中。

这是“scrollUp”功能代码:(记住,这是使用Xcode for iphone的objective-c):

-(void)scrollUp {
    if(fireball.center.y < scrollLine) {
    //sets up variables for background movement to add to.
    float oldXB1 = background1.center.x;
    float oldYB1 = background1.center.y;
    float oldXB2 = background2.center.x;
    float oldYB2 = background2.center.y;

         //makes "players" velocity go in the downward direction (disregard for question)
    velocity.y += .25;

    //sets up a for loop which tests each platform individually
         //[platformHolder] holds all 5 platforms
    for (int i = 0; i < [platformHolder count]; i++) {
    UIImageView *temp = (UIImageView *)[platformHolder objectAtIndex:i];
    if(fireball.center.y > 0) {
        temp.center = CGPointMake(temp.center.x, temp.center.y + 4);
    }
    if(fireball.center.y < 0) {
        temp.center = CGPointMake(temp.center.x, temp.center.y + 8);
        velocity.y += .03;
    }
    if(temp.center.y >  480) {
        scoreNum += 10;
        score.text =[NSString stringWithFormat:@"Score: %i", scoreNum];
        temp.center = CGPointMake(arc4random() % randomNumMax, 0);
    }
    }

    if(fireball.center.y > 0) {
        background1.center = CGPointMake(oldXB1, oldYB1 + velocityB1.y);
        background2.center = CGPointMake(oldXB2, oldYB2 + velocityB2.y);
    }

    if(fireball.center.y < 0) {
        background1.center = CGPointMake(oldXB1, oldYB1 + velocityB1.y);
        background2.center = CGPointMake(oldXB2, oldYB2 + velocityB2.y);
    }

    if(background1.center.y > (480 + background1.center.y/2)) {
        background1.center = CGPointMake(background1.center.x, -1*background1.center.y );
    }
    if(background2.center.y > (480 + background2.center.y/2)) {
         background2.center = CGPointMake(background2.center.x, -1*background2.center.y );
    }       
    }
}

0 个答案:

没有答案