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

nickculbertson

macrumors regular
Original poster
Nov 19, 2010
226
0
Nashville, TN
Hello,
I'm trying to work out how to do this in my head and I'm stuck. I have a View containing 15 different UIImageViews (5 by 3) where each UIImageView shows a flipbook style animation. Covering each UIImageView there is a UIButton that when touched will become hidden revealing the new animation while ending the first animation. I only want up to 5 animation loops playing at a time (one per row). If a button is pushed selecting another animation to begin, that animation should begin only after the currently playing animation in that row is complete. "L1-L5"(below) are UILabel's I'm using to show which animations to play based on a number. Here is what I have so far:

Code:
- (IBAction)lighton1{
L1.text=@"1";}
- (IBAction)lighton2{
L1.text=@"2";}
- (IBAction)lighton3{
L1.text=@"3";}
- (IBAction)lighton4{
L2.text=@"1";}
- (IBAction)lighton5{
L2.text=@"2";}
- (IBAction)lighton6{
L2.text=@"3";}
- (IBAction)lighton7{
L3.text=@"1";}
- (IBAction)lighton8{
L3.text=@"2";}
- (IBAction)lighton9{
L3.text=@"3";}
- (IBAction)lighton10{
L4.text=@"1";}
- (IBAction)lighton11{
L4.text=@"2";}
- (IBAction)lighton12{
L4.text=@"3";}
- (IBAction)lighton13{
L5.text=@"1";}
- (IBAction)lighton14{
L5.text=@"2";}
- (IBAction)lighton15{
L5.text=@"3";}

- (void)animateImages{
	
	UIImage *Image1 = [UIImage imageNamed:@"playbanjoguy1e.png"];
	UIImage *Image2 = [UIImage imageNamed:@"playbanjoguy1f.png"];
	UIImage *Image3 = [UIImage imageNamed:@"playbanjoguy1g.png"];
	UIImage *Image4 = [UIImage imageNamed:@"playbanjoguy1h.png"];
	UIImage *Image5 = [UIImage imageNamed:@"playbanjoguy2e.png"];
	UIImage *Image6 = [UIImage imageNamed:@"playbanjoguy2f.png"];
	UIImage *Image7 = [UIImage imageNamed:@"playbanjoguy2g.png"];
	UIImage *Image8 = [UIImage imageNamed:@"playbanjoguy2h.png"];
	UIImage *Image9 = [UIImage imageNamed:@"playbanjoguy2i.png"];
	UIImage *Image10 = [UIImage imageNamed:@"playbanjoguy2j.png"];
	UIImage *Image11 = [UIImage imageNamed:@"playbanjoguy2k.png"];
	UIImage *Image12 = [UIImage imageNamed:@"playbanjoguy2l.png"];
	UIImage *Image13 = [UIImage imageNamed:@"playbanjoguy2m.png"];
	UIImage *Image14 = [UIImage imageNamed:@"playbanjoguy2n.png"];
	UIImage *Image15 = [UIImage imageNamed:@"playbanjoguy2o.png"];
	UIImage *Image16 = [UIImage imageNamed:@"playbanjoguy2p.png"];
	
	if(images.image == Image1)
		images.image = Image2;
	else if(images.image == Image2)
		images.image = Image3;
	else if(images.image == Image3)
		images.image = Image4;
	else if(images.image == Image4)
		images.image = Image5;
	else if(images.image == Image5)
		images.image = Image6;
	else if(images.image == Image6)
		images.image = Image7;
	else if(images.image == Image7)
		images.image = Image8;
	else if(images.image == Image8)
		images.image = Image9;
	else if(images.image == Image9)
		images.image = Image10;
	else if(images.image == Image10)
		images.image = Image11;
	else if(images.image == Image11)
		images.image = Image12;
	else if(images.image == Image12)
		images.image = Image13;
	else if(images.image == Image13)
		images.image = Image14;
	else if(images.image == Image14)
		images.image = Image15;
	else if(images.image == Image15){
		images.image = Image16;
		// I think I want some code here to start the new animation
	}
	else
		images.image = Image1;
	
}

-(void) guy1{
	if (L1.text==@"1"){
		//play sound
		//hide Button
		if (animationTimer2) {
			[animationTimer2 invalidate];
		}
		if (animationTimer3) {
			[animationTimer3 invalidate];
		}
	}else if(L1.text==@"2"){
		//play sound2
		if (animationTimer) {
		[animationTimer invalidate];
		}
		if (animationTimer3) {
			[animationTimer3 invalidate];
		}
	}else if(L1.text==@"3"){
		//play sound3
		
		
	}
	
}


- (void)tick{
	[self animateImages];
}

- (void)tick2{
	[self animateImages2];
}
- (void)tick3{
	[self animateImages3];
}
- (void)tick4{
	[self animateImages4];
}
- (void)tick5{
	[self animateImages5];
}
- (void)tick6{
	[self animateImages6];
}
- (void)tick7{
	[self animateImages7];
}
- (void)tick8{
	[self animateImages8];
}
- (void)tick9{
	[self animateImages9];
}
- (void)tick10{
	[self animateImages10];
}
- (void)tick11{
	[self animateImages11];
}
- (void)tick12{
	[self animateImages12];
}
- (void)tick13{
	[self animateImages13];
}
- (void)tick14{
	[self animateImages14];
}
- (void)tick15{
	[self animateImages15];
}


- (void)viewDidLoad {
	L1.text=@"1";
	animationTimer = [NSTimer scheduledTimerWithTimeInterval:(2.0/25.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];
	
	
    [super viewDidLoad];
}

How do I get the second animation to begin after the first one ends? I hope this kind of makes sense. Any thoughts will be greatly appreciated.

Thanks,
Nick
 
Last edited:
How do I get the second animation to begin after the first one ends? I hope this kind of makes sense. Any thoughts will be greatly appreciated.
Just a thought.

Can you raise a flag (say something like rowbusy1 to rowbusy5) when you start an animation (where you select Image1) in a given row and then drop the flag when it is done (where you say "I think I want some code here to start the new animation").

That way you can check the flag status before deciding whether to process the next UIbutton touch or not.

B
 
Thanks balamw!

I was thinking something similar and I just now got it to work. I had to create a few more labels but I'm pleased with the result.

Code:
- (IBAction)lighton1{
L1.text=@"1";
	
}

- (IBAction)lighton2{
L1.text=@"2";
	
}


- (void)animateImages{
	
	if (L2.text==@"1"){
	
	UIImage *Image1 = [UIImage imageNamed:@"playbanjoguy1e.png"];
	UIImage *Image2 = [UIImage imageNamed:@"playbanjoguy1f.png"];
	UIImage *Image3 = [UIImage imageNamed:@"playbanjoguy1g.png"];
	UIImage *Image4 = [UIImage imageNamed:@"playbanjoguy1h.png"];
	UIImage *Image5 = [UIImage imageNamed:@"playbanjoguy2e.png"];
	UIImage *Image6 = [UIImage imageNamed:@"playbanjoguy2f.png"];
	UIImage *Image7 = [UIImage imageNamed:@"playbanjoguy2g.png"];
	UIImage *Image8 = [UIImage imageNamed:@"playbanjoguy2h.png"];
	UIImage *Image9 = [UIImage imageNamed:@"playbanjoguy2i.png"];
	UIImage *Image10 = [UIImage imageNamed:@"playbanjoguy2j.png"];
	UIImage *Image11 = [UIImage imageNamed:@"playbanjoguy2k.png"];
	UIImage *Image12 = [UIImage imageNamed:@"playbanjoguy2l.png"];
	UIImage *Image13 = [UIImage imageNamed:@"playbanjoguy2m.png"];
	UIImage *Image14 = [UIImage imageNamed:@"playbanjoguy2n.png"];
	UIImage *Image15 = [UIImage imageNamed:@"playbanjoguy2o.png"];
	UIImage *Image16 = [UIImage imageNamed:@"playbanjoguy2p.png"];
	
	
	
	if(images.image == Image1)
		images.image = Image2;
	else if(images.image == Image2)
		images.image = Image3;
	else if(images.image == Image3)
		images.image = Image4;
	else if(images.image == Image4)
		images.image = Image5;
	else if(images.image == Image5)
		images.image = Image6;
	else if(images.image == Image6)
		images.image = Image7;
	else if(images.image == Image7)
		images.image = Image8;
	else if(images.image == Image8)
		images.image = Image9;
	else if(images.image == Image9)
		images.image = Image10;
	else if(images.image == Image10)
		images.image = Image11;
	else if(images.image == Image11)
		images.image = Image12;
	else if(images.image == Image12)
		images.image = Image13;
	else if(images.image == Image13)
		images.image = Image14;
	else if(images.image == Image14)
		images.image = Image15;
	else if(images.image == Image15){
		images.image = Image16;
		
		CFBundleRef mainBundle = CFBundleGetMainBundle();
		CFURLRef soundFileURLRef;
		
		if (L1.text==@"1"){
			L2.text=@"1";
		}else if (L1.text==@"2") {
			L2.text=@"2";
		}
			
		
		int Number = rand() % 3;
		switch (Number) {
			case 0:
				soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Loop1", CFSTR("wav"), NULL);
				UInt32 soundID;
				AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
				AudioServicesPlaySystemSound(soundID);
				break;
			case 1:
				soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Loop2", CFSTR("wav"), NULL);
				UInt32 soundID2;
				AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID2);
				AudioServicesPlaySystemSound(soundID2);
				break;
			case 2:
				soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Loop3", CFSTR("wav"), NULL);
				UInt32 soundID3;
				AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID3);
				AudioServicesPlaySystemSound(soundID3);
				break;
			default:
			break;
		}
			
		}
		
	
	else
		images.image = Image1;
	}
	else if (L2.text==@"2"){
		UIImage *Image1 = [UIImage imageNamed:@"playbanjoguy1a.png"];
		UIImage *Image2 = [UIImage imageNamed:@"playbanjoguy1b.png"];
		UIImage *Image3 = [UIImage imageNamed:@"playbanjoguy1c.png"];
		UIImage *Image4 = [UIImage imageNamed:@"playbanjoguy1d.png"];
		UIImage *Image5 = [UIImage imageNamed:@"playbanjoguy1e.png"];
		UIImage *Image6 = [UIImage imageNamed:@"playbanjoguy1f.png"];
		UIImage *Image7 = [UIImage imageNamed:@"playbanjoguy1g.png"];
		UIImage *Image8 = [UIImage imageNamed:@"playbanjoguy1h.png"];
		UIImage *Image9 = [UIImage imageNamed:@"playbanjoguy1i.png"];
		UIImage *Image10 = [UIImage imageNamed:@"playbanjoguy1j.png"];
		UIImage *Image11 = [UIImage imageNamed:@"playbanjoguy1k.png"];
		UIImage *Image12 = [UIImage imageNamed:@"playbanjoguy1l.png"];
		UIImage *Image13 = [UIImage imageNamed:@"playbanjoguy1m.png"];
		UIImage *Image14 = [UIImage imageNamed:@"playbanjoguy1n.png"];
		UIImage *Image15 = [UIImage imageNamed:@"playbanjoguy1o.png"];
		UIImage *Image16 = [UIImage imageNamed:@"playbanjoguy1p.png"];
		
		
		
		if(images2.image == Image1)
			images2.image = Image2;
		else if(images2.image == Image2)
			images2.image = Image3;
		else if(images2.image == Image3)
			images2.image = Image4;
		else if(images2.image == Image4)
			images2.image = Image5;
		else if(images2.image == Image5)
			images2.image = Image6;
		else if(images2.image == Image6)
			images2.image = Image7;
		else if(images2.image == Image7)
			images2.image = Image8;
		else if(images2.image == Image8)
			images2.image = Image9;
		else if(images2.image == Image9)
			images2.image = Image10;
		else if(images2.image == Image10)
			images2.image = Image11;
		else if(images2.image == Image11)
			images2.image = Image12;
		else if(images2.image == Image12)
			images2.image = Image13;
		else if(images2.image == Image13)
			images2.image = Image14;
		else if(images2.image == Image14)
			images2.image = Image15;
		else if(images2.image == Image15){
			images2.image = Image16;
			CFBundleRef mainBundle = CFBundleGetMainBundle();
			CFURLRef soundFileURLRef;
			if (L1.text==@"1"){
				L2.text=@"1";
			}else if (L1.text==@"2") {
				L2.text=@"2";
			} 
			
			int Number = rand() % 3;
			switch (Number) {
				case 0:
					soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Loop4", CFSTR("wav"), NULL);
					UInt32 soundID;
					AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
					AudioServicesPlaySystemSound(soundID);
					break;
				case 1:
					soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Loop5", CFSTR("wav"), NULL);
					UInt32 soundID2;
					AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID2);
					AudioServicesPlaySystemSound(soundID2);
					break;
				case 2:
					soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Loop6", CFSTR("wav"), NULL);
					UInt32 soundID3;
					AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID3);
					AudioServicesPlaySystemSound(soundID3);
					break;
				default:
					break;
			
			
			}
			
		}
		else
			images2.image = Image1;
		}
}


- (void)tick{
	[self animateImages];
}

- (void)tick2{
	[self animateImages2];
}
- (void)tick3{
	[self animateImages3];
}
- (void)tick4{
	[self animateImages4];
}
- (void)tick5{
	[self animateImages5];
}






- (void)viewDidLoad {
	L2.text=@"1";
	animationTimer = [NSTimer scheduledTimerWithTimeInterval:(2.0/25.0) target:self selector:@selector(animateImages) userInfo:nil repeats:YES];
	
	
    [super viewDidLoad];
}

Thanks,
Nick
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.