What is the best way to make a bouncing ball animation with infinite loop on iPhone?

后端 未结 3 1351
有刺的猬
有刺的猬 2020-12-16 08:44

I am developing an iPhone game in which birds bounce.

I have set up the images for animating the wings of the flying bird like this:

[imgBird[i] set         


        
3条回答
  •  無奈伤痛
    2020-12-16 09:22

    From your question it seems you are using more than one timer. Use just one to animate all your objects. Somewhere, when your app starts, have this:

    [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(mainLoop:) userInfo:nil repeats:YES];
    

    Then, in main loop, something like this:

    - (void)mainLoop:(NSTimer *)timer
    {
        // compute new position for imgBirds
        for (int i=0; i

    Also, you should compute somex and somey as a function of your timer interval. In that way, if you change it, your animation will still look the same.

提交回复
热议问题