views:

32

answers:

0

I am developing a "doodle jump" like game and i have 5 platforms on the screen on at a time. there are two background UIImageViews. I have the "scrollUp" function called whenever the player is in the top 3/4's of the screen. when the backgrounds are in view, the game slows down and lags, when the backgrounds are out of view (have scolled away), the game runs smooth and fine. I tried disabling the actual code that made them move and it still lagged, the background images are both png's that i created in photoshop and are each in an individual UIImageView. here is the "scrollUp" function code: (remember, this is objective-c using 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 );

    }





}

}