Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

boyplunder

macrumors regular
Original poster
Sep 8, 2008
165
0
UK
Hi All,
I have given myself the task [This is in learning mode!] to create a very simple game where, for the moment, three small animations appear one after the other in different parts of the screen. The user has to touch each item as they appear.

I have not done any timer work before, hence the self-inflicted exercise. I have set up a timer that plays the first animation method, but can't figure out how to set off the other two, once this one has finished. I can loop the first one pretty easy, but how do I reference the other two in the timer? The end of one should be the beginning of the next. Do I use multiple timers run inside the initial timer?
 
boyplunder said:
... how do I reference the other two in the timer? The end of one should be the beginning of the next. Do I use multiple timers run inside the initial timer?

There is a delegate for that... You can set a delegate before starting the animation that get's called when the animation is ready. You do the animation with UIView beginAnimation and commitAnimation, do you? Read about it... that helps.
 
I have not done any timer work before, hence the self-inflicted exercise. I have set up a timer that plays the first animation method, but can't figure out how to set off the other two, once this one has finished. I can loop the first one pretty easy, but how do I reference the other two in the timer? The end of one should be the beginning of the next. Do I use multiple timers run inside the initial timer?
Does the first timer repeat or are you just firing it once? If the former, what are you doing to stop the repeating? Perhaps at that point you can fire off the next timer...

Also, be aware that timers are not guaranteed to fire exactly at the specified interval. They are dependent on the run loop timing. If you need exact timing, you may need to consider alternatives.
 
i've accomplished animation timing like this:

Code:
- (void)animationDidStop:(NSString *)animationID
	{
	if ([animationID isEqualToString:@"fadeShapeAnimation"])
		NSLog(@"fadeShapeAnimation Finished Animating");
	}

- (void)fadeShapeToAlpha:(float)fadeAlpha withDuration:(float)duration
	{
	[UIView beginAnimations:@"fadeShapeAnimation" context:NULL];
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(animationDidStop:)];
	[UIView setAnimationCurve:UIViewAnimationCurveLinear];
	[UIView setAnimationDuration:duration];

	myShape.alpha = fadeAlpha;

	[UIView commitAnimations];
	}

read about CAAffineTransform to accomplish rotation, scaling and translation (moving). alternatively, rather than using a translation to move your view, you can simply set new frame coordinates inside the animation block (between beginAnimations and commitAnimations).
 
chbeer, I will look into the delegate route. I have read through a fair old chunk of the dev centre on this subject, but this part is all a bit new to me and I seem to be thinking it's far more complicated than it is, so hopefully RobbieDuncan won't come on and say 'Read the documentation...!"

Have not done any animation or touch controls yet, certainly not in a game sense.

dejo, for the moment I want to run each of the animations one after the other. I have two nearly identical animations that I am trying to play with. I have set up a timer that plays one animation, and made it loop, but can't see how to manage multiple animations, and that's where I'm getting stuck.

darkroom, that's very helpful. Yes I was thinking I could assign different coordinates for each animation appearance, but one thing at a time I think.

Maybe I should take a nap and come back to it.
 
dejo, for the moment I want to run each of the animations one after the other. I have two nearly identical animations that I am trying to play with. I have set up a timer that plays one animation, and made it loop, but can't see how to manage multiple animations, and that's where I'm getting stuck.
What I was trying to find out (sorry, maybe I wasn't clear) was whether you're using the repeats option of initWithFireDate:interval:target:selector:userInfo:repeats:. Sounds like you are. Are you doing anything to stop the animation?

Also, just to be clear, what kind of animation are we talking about here? Motion animation or image animation or what?
 
what kind of animation are we talking about here? Motion animation or image animation or what?

I have set up an NSArray arrayWithObjects that refers to five images and called it myflash. I have used this initially in an NSTimer. It loops every whatever using a repeat.

The next step is to manage more than one, so this could be up to 20 or 30 on the same view. That's where I come unstuck. I can't find a way of doing this in the dev centre, or I just don't know what I'm looking for and have read it a couple of times.
 
Have you looked at UIImageView's animation properties (animationImages, etc.) and its startAnimating and stopAnimating instance methods? That might get you the effect you want without the need for an NSTimer.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.