Building a Game Loop in iPhone and iPad Game Development

3 71

A game loop gets your code to update the game world on your iPhone or iPad many times a second — fast enough to make it look like fluid motion to the player.
To do this, you need to update the position of all your views every time the screen is redrawn by iOS. To be notified of when this happens, you need to use a CADisplayLink class. CADisplayLink is an object that, when you create it, sends your class a message just before the screen is about to update. This gives you the opportunity to move your views around.
To set up a CADisplayLink.

  1. Create a method that gets called when the screen updates; make the method look like this:
    (void) update:(CADisplayLink*)displayLink {
    }

  2. When your view is loaded, create and prepare a CADisplayLink object by adding this code to the viewDidLoad: method in your view controller’s .m file:
    displayLink = [CADisplayLink displayLinkWithTarget:self 
    selector:@selector(update:)];
    [displayLink addToRunLoop:[NSRunLoop mainRunLoop]
    forMode:NSRunLoopCommonModes];

When your view loads, you receive the update: message many times a second, which is your opportunity to update the game world.



Related Articles: More from author

  1. Anonymous says

    You're so awesome! I don't believe I have read something
    like this before. So wonderful to find another person with some unique thoughts on
    this subject matter. Really.. many thanks for starting this up.

    This website is something that is needed on the internet, someone with a little originality!
    streetdirectory

  2. Anonymous says

    Defіnitely bеliеve that which you ѕaid.

    Your favourite justification seemeԁ to be at the net the easіest factor to take note of.
    I sаy to you, I certainly get annoyеԁ at the same time
    as folks think аbout worries that they just do not knoω аbout.
    You mаnageԁ to hit the nail uрon the toρ and also defined out the ωhole
    thing without having sidе effeсt , people could take а signal.

    Will probably bе back to get mοre.

    Thankѕ

    my homepagе :: http://bikeraсeсheats.
    com/ ()

Leave A Reply

Your email address will not be published.