1

我正在开发一个类似“涂鸦跳跃”的游戏,我在屏幕上一次有 5 个平台。有两个背景 UIImageViews。我有“scrollUp”功能,只要玩家位于屏幕的顶部 3/4 时就会调用该功能。当背景在视野中时,游戏会变慢并滞后,当背景不在视野中(已经滚开)时,游戏运行流畅且良好。我尝试禁用使它们移动的实际代码,但它仍然滞后,背景图像都是我在 photoshop 中创建的 png,并且每个都在单独的 UIImageView 中。

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

-(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 );
    }       
    }
}
4

0 回答 0