Search code examples
iphoneobjective-ciosxcode4

trying to program a similar app like line runner


im a newbie in the IOS and macOsx development. I have an assignment left to me by one a instructor helping us get the basic of iPhone development. he wants us to duplicate the line runner up. obviously for educational purpose only. now her are my problems or the issues i have that i have no clue of how to get started. If you guys can show me any tutorials that might help me or aid through this. it would be greatly appreciate it.

1- dont know how to generate a moving background./ 2- i know how to make my png move around the screen but have yet learn how tell them to do something when they touch. (so jumping i got it cover but not when he touches an object.

thanks for all of you guys that can help.


Solution

  • I'm not sure if this is the answer you're looking for, but for the moving background what you can do is make a really wide image, and then move that image programmatically by using something like the following:

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:x];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationRepeatCount:y];
    imageX.transform = CGAffineTransformMakeTranslation(5,0);
    [UIView commitAnimations];
    

    This will make your image move for a certain amount of time, you can even set it to repeat if you want.

    Another approach is to make frames of the animation you'd like to create, for example you would make 20 Images for the background animation and then use something like the following:

    imageX.animationImages = [NSArray arrayWithObjects:
     [UIImage imageNamed:@"img1.png"], //You would go all the way up to 20
     [UIImage imageNamed:@"img2.png"],
     [UIImage imageNamed:@"img3.png"],
     [UIImage imageNamed:@"img4.png"], nil];
    
    [imageX setAnimationDuration:x];
    [imageX setAnimationRepeatCount:20];
    [imageX startAnimating];
    

    To tell your player to do something when he touches another object you could use something like the following:

    if (CGRectIntersectsRect(player.frame, enemy.frame)) {
        //Collision Detected
        //Code Goes Here
    }