PDA

View Full Version : [Resolved] Animation Loop with Audio




nickculbertson
Mar 31, 2011, 01:08 PM
Hello,
I have an animation loop with audio being triggered by the frame the animation is on. The problem is that the audio plays once for every four times the animation loop plays. My solution was to add 3 duplicates for each animation frame but this has zapped up all of my memory. Is there a more efficient way to do this only using 16 images instead of (16X4) 64 images.

- (void)animateImages{

UIImage *Image1 = [UIImage imageNamed:@"beat1copy.png"];
UIImage *Image2 = [UIImage imageNamed:@"beat2copy.png"];
UIImage *Image3 = [UIImage imageNamed:@"beat3copy.png"];
UIImage *Image4 = [UIImage imageNamed:@"beat4copy.png"];
UIImage *Image5 = [UIImage imageNamed:@"beat5copy.png"];
UIImage *Image6 = [UIImage imageNamed:@"beat6copy.png"];
UIImage *Image7 = [UIImage imageNamed:@"beat7copy.png"];
UIImage *Image8 = [UIImage imageNamed:@"beat8copy.png"];
UIImage *Image9 = [UIImage imageNamed:@"beat9copy.png"];
UIImage *Image14 = [UIImage imageNamed:@"beat10copy.png"];
UIImage *Image15 = [UIImage imageNamed:@"beat11copy.png"];
UIImage *Image16 = [UIImage imageNamed:@"beat12copy.png"];
UIImage *Image17 = [UIImage imageNamed:@"beat13copy.png"];
UIImage *Image18 = [UIImage imageNamed:@"beat14copy.png"];
UIImage *Image19 = [UIImage imageNamed:@"beat15copy.png"];
UIImage *Image20 = [UIImage imageNamed:@"beat16copy.png"];
UIImage *Image21 = [UIImage imageNamed:@"beat1copycopy.png"];
UIImage *Image22 = [UIImage imageNamed:@"beat2copycopy.png"];
UIImage *Image23 = [UIImage imageNamed:@"beat3copycopy.png"];
UIImage *Image24 = [UIImage imageNamed:@"beat4copycopy.png"];
UIImage *Image25 = [UIImage imageNamed:@"beat5copycopy.png"];
UIImage *Image26 = [UIImage imageNamed:@"beat6copycopy.png"];
UIImage *Image27 = [UIImage imageNamed:@"beat7copycopy.png"];
UIImage *Image28 = [UIImage imageNamed:@"beat8copycopy.png"];
UIImage *Image29 = [UIImage imageNamed:@"beat9copycopy.png"];
UIImage *Image30 = [UIImage imageNamed:@"beat10copycopy.png"];
UIImage *Image31 = [UIImage imageNamed:@"beat11copycopy.png"];
UIImage *Image32 = [UIImage imageNamed:@"beat12copycopy.png"];
UIImage *Image33 = [UIImage imageNamed:@"beat13copycopy.png"];
UIImage *Image34 = [UIImage imageNamed:@"beat14copycopy.png"];
UIImage *Image35 = [UIImage imageNamed:@"beat15copycopy.png"];
UIImage *Image36 = [UIImage imageNamed:@"beat16copycopy.png"];
UIImage *Image37 = [UIImage imageNamed:@"beat1 copy.png"];
UIImage *Image38 = [UIImage imageNamed:@"beat2 copy.png"];
UIImage *Image39 = [UIImage imageNamed:@"beat3 copy.png"];
UIImage *Image40 = [UIImage imageNamed:@"beat4 copy.png"];
UIImage *Image41 = [UIImage imageNamed:@"beat5 copy.png"];
UIImage *Image42 = [UIImage imageNamed:@"beat6 copy.png"];
UIImage *Image43 = [UIImage imageNamed:@"beat7 copy.png"];
UIImage *Image44 = [UIImage imageNamed:@"beat8 copy.png"];
UIImage *Image45 = [UIImage imageNamed:@"beat9 copy.png"];
UIImage *Image46 = [UIImage imageNamed:@"beat10 copy.png"];
UIImage *Image47 = [UIImage imageNamed:@"beat11 copy.png"];
UIImage *Image48 = [UIImage imageNamed:@"beat12 copy.png"];
UIImage *Image49 = [UIImage imageNamed:@"beat13 copy.png"];
UIImage *Image50 = [UIImage imageNamed:@"beat14 copy.png"];
UIImage *Image51 = [UIImage imageNamed:@"beat15 copy.png"];
UIImage *Image52 = [UIImage imageNamed:@"beat16 copy.png"];
UIImage *Image53 = [UIImage imageNamed:@"beat1.png"];
UIImage *Image54 = [UIImage imageNamed:@"beat2.png"];
UIImage *Image55 = [UIImage imageNamed:@"beat3.png"];
UIImage *Image56 = [UIImage imageNamed:@"beat4.png"];
UIImage *Image57 = [UIImage imageNamed:@"beat5.png"];
UIImage *Image58 = [UIImage imageNamed:@"beat6.png"];
UIImage *Image59 = [UIImage imageNamed:@"beat7.png"];
UIImage *Image60 = [UIImage imageNamed:@"beat8.png"];
UIImage *Image61 = [UIImage imageNamed:@"beat9.png"];
UIImage *Image62 = [UIImage imageNamed:@"beat10.png"];
UIImage *Image63 = [UIImage imageNamed:@"beat11.png"];
UIImage *Image64 = [UIImage imageNamed:@"beat12.png"];
UIImage *Image65 = [UIImage imageNamed:@"beat13.png"];
UIImage *Image66 = [UIImage imageNamed:@"beat14.png"];
UIImage *Image67 = [UIImage imageNamed:@"beat15.png"];
UIImage *Image68 = [UIImage imageNamed:@"beat16.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 = Image14;
else if(images.image == Image14)
images.image = Image15;
else if(images.image == Image15)
images.image = Image16;
else if(images.image == Image16)
images.image = Image17;
else if(images.image == Image17)
images.image = Image18;
else if(images.image == Image18)
images.image = Image19;
else if(images.image == Image19)
images.image = Image20;
else if(images.image == Image20)
images.image = Image21;
else if(images.image == Image21)
images.image = Image22;
else if(images.image == Image22)
images.image = Image23;
else if(images.image == Image23)
images.image = Image24;
else if(images.image == Image24)
images.image = Image25;
else if(images.image == Image25)
images.image = Image26;
else if(images.image == Image26)
images.image = Image27;
else if(images.image == Image27)
images.image = Image28;
else if(images.image == Image28)
images.image = Image29;
else if(images.image == Image29)
images.image = Image30;
else if(images.image == Image30)
images.image = Image31;
else if(images.image == Image31)
images.image = Image32;
else if(images.image == Image32)
images.image = Image33;
else if(images.image == Image33)
images.image = Image34;
else if(images.image == Image34)
images.image = Image35;
else if(images.image == Image35)
images.image = Image36;
else if(images.image == Image36)
images.image = Image37;
else if(images.image == Image37)
images.image = Image38;
else if(images.image == Image38)
images.image = Image39;
else if(images.image == Image39)
images.image = Image40;
else if(images.image == Image40)
images.image = Image41;
else if(images.image == Image41)
images.image = Image42;
else if(images.image == Image42)
images.image = Image43;
else if(images.image == Image43)
images.image = Image44;
else if(images.image == Image44)
images.image = Image45;
else if(images.image == Image45)
images.image = Image46;
else if(images.image == Image46)
images.image = Image47;
else if(images.image == Image47)
images.image = Image48;
else if(images.image == Image48)
images.image = Image49;
else if(images.image == Image49)
images.image = Image50;
else if(images.image == Image50)
images.image = Image51;
else if(images.image == Image51)
images.image = Image52;
else if(images.image == Image52)
images.image = Image53;
else if(images.image == Image53)
images.image = Image54;
else if(images.image == Image54)
images.image = Image55;
else if(images.image == Image55)
images.image = Image56;
else if(images.image == Image56)
images.image = Image57;
else if(images.image == Image57)
images.image = Image58;
else if(images.image == Image58)
images.image = Image59;
else if(images.image == Image59)
images.image = Image60;
else if(images.image == Image60)
images.image = Image61;
else if(images.image == Image61)
images.image = Image62;
else if(images.image == Image62)
images.image = Image63;
else if(images.image == Image63)
images.image = Image64;
else if(images.image == Image64)
images.image = Image65;
else if(images.image == Image65)
images.image = Image66;
else if(images.image == Image66)
images.image = Image67;
else if(images.image == Image67){
images.image = Image68;
// ******play audio******
}else{images.image = Image1;}
}

- (void)viewDidLoad {
animationTimer = [NSTimer scheduledTimerWithTimeInterval:(2.0/32.0) target:self selector:@selector(animateImages) userInfo:nil repeats:YES];
}




Thanks,
Nick



dejo
Mar 31, 2011, 01:19 PM
How do you play the audio? I.E. Show us all the code.

nickculbertson
Mar 31, 2011, 02:01 PM
dejo,
Here is a little more of the code. the L2,L4,etc. are labels that are changed by IBAction button presses.


- (void)animateImages{
if (L2.text==@"1"){

UIImage *Image1 = [UIImage imageNamed:@"beat1copy.png"];
UIImage *Image2 = [UIImage imageNamed:@"beat2copy.png"];
UIImage *Image3 = [UIImage imageNamed:@"beat3copy.png"];
UIImage *Image4 = [UIImage imageNamed:@"beat4copy.png"];
UIImage *Image5 = [UIImage imageNamed:@"beat5copy.png"];
UIImage *Image6 = [UIImage imageNamed:@"beat6copy.png"];
UIImage *Image7 = [UIImage imageNamed:@"beat7copy.png"];
UIImage *Image8 = [UIImage imageNamed:@"beat8copy.png"];
UIImage *Image9 = [UIImage imageNamed:@"beat9copy.png"];
//UIImage *Image10 = [UIImage imageNamed:@"banjocartoon10a.png"];
//UIImage *Image11 = [UIImage imageNamed:@"banjocartoon11a.png"];
//UIImage *Image12 = [UIImage imageNamed:@"banjocartoon12a.png"];
//UIImage *Image13 = [UIImage imageNamed:@"banjocartoon13a.png"];
UIImage *Image14 = [UIImage imageNamed:@"beat10copy.png"];
UIImage *Image15 = [UIImage imageNamed:@"beat11copy.png"];
UIImage *Image16 = [UIImage imageNamed:@"beat12copy.png"];
UIImage *Image17 = [UIImage imageNamed:@"beat13copy.png"];
UIImage *Image18 = [UIImage imageNamed:@"beat14copy.png"];
UIImage *Image19 = [UIImage imageNamed:@"beat15copy.png"];
UIImage *Image20 = [UIImage imageNamed:@"beat16copy.png"];
UIImage *Image21 = [UIImage imageNamed:@"beat1copycopy.png"];
UIImage *Image22 = [UIImage imageNamed:@"beat2copycopy.png"];
UIImage *Image23 = [UIImage imageNamed:@"beat3copycopy.png"];
UIImage *Image24 = [UIImage imageNamed:@"beat4copycopy.png"];
UIImage *Image25 = [UIImage imageNamed:@"beat5copycopy.png"];
UIImage *Image26 = [UIImage imageNamed:@"beat6copycopy.png"];
UIImage *Image27 = [UIImage imageNamed:@"beat7copycopy.png"];
UIImage *Image28 = [UIImage imageNamed:@"beat8copycopy.png"];
UIImage *Image29 = [UIImage imageNamed:@"beat9copycopy.png"];
UIImage *Image30 = [UIImage imageNamed:@"beat10copycopy.png"];
UIImage *Image31 = [UIImage imageNamed:@"beat11copycopy.png"];
UIImage *Image32 = [UIImage imageNamed:@"beat12copycopy.png"];
UIImage *Image33 = [UIImage imageNamed:@"beat13copycopy.png"];
UIImage *Image34 = [UIImage imageNamed:@"beat14copycopy.png"];
UIImage *Image35 = [UIImage imageNamed:@"beat15copycopy.png"];
UIImage *Image36 = [UIImage imageNamed:@"beat16copycopy.png"];
UIImage *Image37 = [UIImage imageNamed:@"beat1 copy.png"];
UIImage *Image38 = [UIImage imageNamed:@"beat2 copy.png"];
UIImage *Image39 = [UIImage imageNamed:@"beat3 copy.png"];
UIImage *Image40 = [UIImage imageNamed:@"beat4 copy.png"];
UIImage *Image41 = [UIImage imageNamed:@"beat5 copy.png"];
UIImage *Image42 = [UIImage imageNamed:@"beat6 copy.png"];
UIImage *Image43 = [UIImage imageNamed:@"beat7 copy.png"];
UIImage *Image44 = [UIImage imageNamed:@"beat8 copy.png"];
UIImage *Image45 = [UIImage imageNamed:@"beat9 copy.png"];
UIImage *Image46 = [UIImage imageNamed:@"beat10 copy.png"];
UIImage *Image47 = [UIImage imageNamed:@"beat11 copy.png"];
UIImage *Image48 = [UIImage imageNamed:@"beat12 copy.png"];
UIImage *Image49 = [UIImage imageNamed:@"beat13 copy.png"];
UIImage *Image50 = [UIImage imageNamed:@"beat14 copy.png"];
UIImage *Image51 = [UIImage imageNamed:@"beat15 copy.png"];
UIImage *Image52 = [UIImage imageNamed:@"beat16 copy.png"];
UIImage *Image53 = [UIImage imageNamed:@"beat1.png"];
UIImage *Image54 = [UIImage imageNamed:@"beat2.png"];
UIImage *Image55 = [UIImage imageNamed:@"beat3.png"];
UIImage *Image56 = [UIImage imageNamed:@"beat4.png"];
UIImage *Image57 = [UIImage imageNamed:@"beat5.png"];
UIImage *Image58 = [UIImage imageNamed:@"beat6.png"];
UIImage *Image59 = [UIImage imageNamed:@"beat7.png"];
UIImage *Image60 = [UIImage imageNamed:@"beat8.png"];
UIImage *Image61 = [UIImage imageNamed:@"beat9.png"];
UIImage *Image62 = [UIImage imageNamed:@"beat10.png"];
UIImage *Image63 = [UIImage imageNamed:@"beat11.png"];
UIImage *Image64 = [UIImage imageNamed:@"beat12.png"];
UIImage *Image65 = [UIImage imageNamed:@"beat13.png"];
UIImage *Image66 = [UIImage imageNamed:@"beat14.png"];
UIImage *Image67 = [UIImage imageNamed:@"beat15.png"];
UIImage *Image68 = [UIImage imageNamed:@"beat16.png"];
// UIImage *Image70 = [UIImage imageNamed:@"bluelock.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;
[self hide];
}
else if(images.image == Image9)

images.image = Image14;
else if(images.image == Image14)
images.image = Image15;
else if(images.image == Image15)
images.image = Image16;
else if(images.image == Image16)
images.image = Image17;
else if(images.image == Image17)
images.image = Image18;
else if(images.image == Image18)
images.image = Image19;
else if(images.image == Image19)
images.image = Image20;
else if(images.image == Image20)
images.image = Image21;
else if(images.image == Image21)
images.image = Image22;
else if(images.image == Image22)
images.image = Image23;
else if(images.image == Image23)
images.image = Image24;
else if(images.image == Image24)
images.image = Image25;
else if(images.image == Image25)
images.image = Image26;
else if(images.image == Image26)
images.image = Image27;
else if(images.image == Image27)
images.image = Image28;
else if(images.image == Image28)
images.image = Image29;
else if(images.image == Image29)
images.image = Image30;
else if(images.image == Image30)
images.image = Image31;
else if(images.image == Image31)
images.image = Image32;
else if(images.image == Image32)
images.image = Image33;
else if(images.image == Image33)
images.image = Image34;
else if(images.image == Image34)
images.image = Image35;
else if(images.image == Image35)
images.image = Image36;
else if(images.image == Image36)
images.image = Image37;
else if(images.image == Image37)
images.image = Image38;
else if(images.image == Image38)
images.image = Image39;
else if(images.image == Image39)
images.image = Image40;
else if(images.image == Image40)
images.image = Image41;
else if(images.image == Image41)
images.image = Image42;
else if(images.image == Image42)
images.image = Image43;
else if(images.image == Image43)
images.image = Image44;
else if(images.image == Image44)
images.image = Image45;
else if(images.image == Image45)
images.image = Image46;
else if(images.image == Image46)
images.image = Image47;
else if(images.image == Image47)
images.image = Image48;
else if(images.image == Image48)
images.image = Image49;
else if(images.image == Image49)
images.image = Image50;
else if(images.image == Image50)
images.image = Image51;
else if(images.image == Image51)
images.image = Image52;
else if(images.image == Image52)
images.image = Image53;
else if(images.image == Image53)
images.image = Image54;
else if(images.image == Image54)
images.image = Image55;
else if(images.image == Image55)
images.image = Image56;
else if(images.image == Image56)
images.image = Image57;
else if(images.image == Image57)
images.image = Image58;
else if(images.image == Image58)
images.image = Image59;
else if(images.image == Image59)
images.image = Image60;
else if(images.image == Image60)
images.image = Image61;
else if(images.image == Image61)
images.image = Image62;
else if(images.image == Image62)
images.image = Image63;
else if(images.image == Image63)
images.image = Image64;
else if(images.image == Image64)
images.image = Image65;
else if(images.image == Image65)
images.image = Image66;
else if(images.image == Image66){
images.image = Image67;
//imagesb.hidden=YES;
//imagesb.image = Image69;
}
else if(images.image == Image67){
images.image = Image68;
if (L4.text==@"1"){

[self lighton1];



L4.text=@"6";


}else if (L4.text==@"2"){
L2.text=@"2";

images1.hidden=YES;
images2.hidden=YES;
images3.hidden=YES;
images17.hidden=YES;
images18.hidden=YES;
images19.hidden=YES;
images20.hidden=YES;

}else if (L4.text==@"3"){
L2.text=@"3";

images1.hidden=YES;
images2.hidden=YES;
images3.hidden=YES;
images17.hidden=YES;
images18.hidden=YES;
images19.hidden=YES;
images20.hidden=YES;

}else if (L4.text==@"4"){
L2.text=@"4";

images1.hidden=YES;
images2.hidden=YES;
images3.hidden=YES;
images17.hidden=YES;
images18.hidden=YES;
images19.hidden=YES;
images20.hidden=YES;

}else if (L4.text==@"5"){
L2.text=@"5";

images1.hidden=YES;
images2.hidden=YES;
images3.hidden=YES;
images17.hidden=YES;
images18.hidden=YES;
images19.hidden=YES;
images20.hidden=YES;


}else if (L4.text==@"6"){


}
}

else{

if (L1.text==@"1") {
images.image = Image1;
images1.hidden=YES;
images2.hidden=NO;
images3.hidden=NO;
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
UInt32 soundID;
int Number = arc4random() % 9;
switch (Number) {
case 0:
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"bluegrassloop1", CFSTR("wav"), NULL);
//UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
break;
case 1:
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"bluegrassloop2", CFSTR("wav"), NULL);
//UInt32 soundID2;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
break;
case 2:
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"bluegrassloop3", CFSTR("wav"), NULL);
//UInt32 soundI3;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
break;
case 3:
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"bluegrassloop4", CFSTR("wav"), NULL);
//UInt32 soundID4;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
break;
case 4:
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"bluegrassloop5", CFSTR("wav"), NULL);
//UInt32 soundID5;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
break;
case 5:
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"bluegrassloop6", CFSTR("wav"), NULL);
//UInt32 soundID6;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
break;
case 6:
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"bluegrassloop1", CFSTR("wav"), NULL);
//UInt32 soundID7;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
break;
case 7:
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"bluegrassloop2", CFSTR("wav"), NULL);
//UInt32 soundID8;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
break;
case 8:
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"bluegrassloop3", CFSTR("wav"), NULL);
///UInt32 soundID9;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
break;
default:
break;

}

}else if (L1.text==@"2") {//... post was too long to post the entire thing.


Thanks,
Nick

dejo
Mar 31, 2011, 02:16 PM
And what triggers animateImages getting called?

Also, if (L1.text == @"1") is not the recommended way to compare strings for equality. You should be using NSString's isEqualToString:.

nickculbertson
Mar 31, 2011, 02:25 PM
I have several buttons covering portions of the animation and when they are touched they hide as the new music loop starts. animateImages is called in the viewDidLoad with an NSTimer.





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

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

}
- (IBAction)lighton3{
L1.text=@"3";

}
- (IBAction)lighton4{
L1.text=@"4";
L4.text=@"2";

}
- (IBAction)lighton5{
L1.text=@"4";
L4.text=@"3";
}
- (IBAction)lighton6{
L1.text=@"4";
L4.text=@"4";
}
- (IBAction)lighton7{
L1.text=@"4";
L4.text=@"5";
}

- (void)viewDidLoad {
animationTimer = [NSTimer scheduledTimerWithTimeInterval:(2.0/32.0) target:self selector:@selector(animateImages) userInfo:nil repeats:YES];
}



As for the isEqualToString: thing, I personally prefer doing it my way. It has always worked fine for me and I don't get any warnings back. Any ideas on the animation?

Thanks,
Nick

PhoneyDeveloper
Mar 31, 2011, 03:21 PM
Hey ever heard of an array? What if you wanted to animate 1000 images? Your code won't scale. Also you can put the same object into multiple positions in the same array.

Dejo is right about the string comparison. If you don't know why he's right then your code, which does work by accident, is likely to not work in the future. On top of that, using the title of a label to make code level decisions is a bad idea.

dejo
Mar 31, 2011, 03:25 PM
As for the isEqualToString: thing, I personally prefer doing it my way. It has always worked fine for me and I don't get any warnings back.
You don't get any warnings or issues because you're lucky that the label text is pointing to the same place in memory as where your hardcoded string is being stored (when you use plain ==, it's the pointers' values that are compared). Consider what would happen with the following code:
NSString *formattedString = [NSString stringWithFormat:@"%d", 1];
if (formattedString == @"1")
...
Should formattedString (which contains @"1") still == @"1"?

Any ideas on the animation?
Not really. I'm confused by how your execution logic either animates images or plays sounds, especially based on the value of a label's text. Maybe explain, perhaps via pseudo-code or just plain English, what you expect to happen when a button is touched.

nickculbertson
Mar 31, 2011, 04:34 PM
Hey ever heard of an array? What if you wanted to animate 1000 images? Your code won't scale. Also you can put the same object into multiple positions in the same array.

The problem with using an array, as far as I know, is that it will not be capable of triggering the audio.


images.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"pic1.png"],
[UIImage imageNamed:@"pic2.png"],
[UIImage imageNamed:@"pic3.png"],
[UIImage imageNamed:@"pic1.png"],
[UIImage imageNamed:@"pic2.png"],
[UIImage imageNamed:@"pic3.png"], nil];


images.animationDuration = .09;

images.animationRepeatCount = 0;

[images startAnimating];


Dejo,
You are right. The reason the pointer works is because I have that label on the interface. It is the same principle as

if(images.image == Image1)
images.image = Image2;
else if(images.image == Image2)
images.image = Image3;


To better explain what I'm trying:

I have a View with 7 buttons and 1 Image View (for the animation). When the View is opened the animation is running in the background but it is hidden behind the buttons. There is also no audio playing at this point. When button 1 is pushed it becomes hidden once the animation returns to the first image in the loop. An audio file starts at the same time the button becomes hidden and is looped until the next button is touched. When the second button is touched the first button becomes unhidden and the second becomes hidden (once the loop returns to the first image). As the second button becomes hidden a new corresponding audio file begins playing. The same goes for button 3.

For buttons 4-7, If one of these buttons are touched all of the masking buttons become hidden and a new animation begins in the Image View with yet another separate audio file. After this loop plays once it self selects the first button again, starting the original animation with the first audio file and the masking buttons unhidden.

I hope this presents the issue a little more clearly.

Thanks,
Nick

PhoneyDeveloper
Mar 31, 2011, 05:31 PM
You can use an array of images in the same way that your current code works.

Create an array with all the images and save this as an ivar/property. Do not set this as the animationImages property. You also need a cursor, call it currentFrame, also ivar/property. Each time you want to set the currentImage in your timer callback increment the currentFrame value, make sure that if it's the same value as the imageList.count you set it to zero so it wraps around, then set the current image to the image at the currentFrame index in your imageList.

I don't understand what you're doing with the audio but you do the same thing you're doing now with it.

nickculbertson
Apr 1, 2011, 12:17 PM
Create an array with all the images and save this as an ivar/property. Do not set this as the animationImages property. You also need a cursor, call it currentFrame, also ivar/property. Each time you want to set the currentImage in your timer callback increment the currentFrame value, make sure that if it's the same value as the imageList.count you set it to zero so it wraps around, then set the current image to the image at the currentFrame index in your imageList.


Thanks Phoney. It always helps to bounce ideas off of you guys. I ended up using an array like you mentioned before and just adjusted my timer to recall that method after the animation looped four times. So now basically what I have is.


-(IBAction)button1{
L2.text=@"1";
}

-(IBAction)button2{
L2.text=@"2";
}

-(void)animateImages{
if (L2.text==@"1"){


images.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"beat1.png"],
[UIImage imageNamed:@"beat2.png"],
[UIImage imageNamed:@"beat3.png"],
[UIImage imageNamed:@"beat4.png"],
[UIImage imageNamed:@"beat5.png"],
[UIImage imageNamed:@"beat6.png"],
[UIImage imageNamed:@"beat7.png"],
[UIImage imageNamed:@"beat8.png"],
[UIImage imageNamed:@"beat9.png"],
[UIImage imageNamed:@"beat10.png"],
[UIImage imageNamed:@"beat11.png"],
[UIImage imageNamed:@"beat12.png"],
[UIImage imageNamed:@"beat13.png"],
[UIImage imageNamed:@"beat14.png"],
[UIImage imageNamed:@"beat15.png"],
[UIImage imageNamed:@"beat16.png"], nil];


images.animationDuration = 64.0/32.0;

images.animationRepeatCount = 4;

[images startAnimating];
//sound1
}else if (L2.text==@"2"){
images.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1cdude.png"],
[UIImage imageNamed:@"2cdude.png"],
[UIImage imageNamed:@"3cdude.png"],
[UIImage imageNamed:@"4cdude.png"],
[UIImage imageNamed:@"5cdude.png"],
[UIImage imageNamed:@"6cdude.png"],
[UIImage imageNamed:@"7cdude.png"],
[UIImage imageNamed:@"8cdude.png"],
[UIImage imageNamed:@"9cdude.png"],
[UIImage imageNamed:@"10cdude.png"],
[UIImage imageNamed:@"11cdude.png"],
[UIImage imageNamed:@"12cdude.png"],
[UIImage imageNamed:@"13cdude.png"],
[UIImage imageNamed:@"14cdude.png"],
[UIImage imageNamed:@"15cdude.png"],
[UIImage imageNamed:@"16cdude.png"], nil];


images.animationDuration = 64.0/32.0;

images.animationRepeatCount = 4;

[images startAnimating];
//sound2
}
}
-(void)viewDidLoad{
L2.text=@"1";

animationTimer = [NSTimer scheduledTimerWithTimeInterval:(64.0/16.0) target:self selector:@selector(animateImages) userInfo:nil repeats:YES];
}


Thanks Again,
Nick