开发者

xcode iphone problem for animating with timers

Hi everyone I'm French so excuse me for my poor English. I'm making a 开发者_JAVA技巧game on the iphone with XCode and what I want to do is make something happen every ten seconds like a ball that jumps. Is there a tutorial for this sample code or example project for this?

Thank you


If you are new to coding on the iPhone or coding in general try out OpenFrameworks for the iPhone. They have great tutorials and have set up a lot of example projects for drawing.


There are a number of example snippets in Apple's Timer Programming Topics: Using Timers. Apple also provides a number of sample projects; the one you might be most interested in is GKRocket, but you can find a list here.


Maybe something like the following:

- (void)animateBall
{
    // Animation for ball jumping.
    // This is just going to move it up and down but it's something to start

    float duration 1.0f;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationRepeatCount:1];
    [UIView setAnimationRepeatAutoreverses:YES];
    [imageView setTransform:CGAffineTransformMakeTranslation(0, 100.0f)];
    [UIView commitAnimations];
}

- (void)run
{
    [NSTimer scheduledTimerWithTimeInterval:10
                                     target:self 
                                   selector:@selector(animateBall) 
                                   userInfo:nil 
                                    repeats:YES];
}

You will probably want an UIImageView containing a UIImage of a ball. You can modify the animation, or link to a secondary animation using UIView's AnimationDidStopSelector.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜