Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-27-2010, 10:50 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Question Randomizing animations?

Hi I have a series of of animation images that i coded using an NSAray. I need to know the best way to randomize those animations so that i don't have to see the same sequence ever time. In the same order. Any Help would be appreciated very much. Thanks
CougarBlitz is offline   Reply With Quote
Old 01-27-2010, 11:04 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by CougarBlitz View Post
Hi I have a series of of animation images that i coded using an NSAray. I need to know the best way to randomize those animations so that i don't have to see the same sequence ever time. In the same order. Any Help would be appreciated very much. Thanks
Search this board for "array shuffle" - I know we've covered it before.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-27-2010, 12:06 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Smile

Hey buddy thanks i will search this right now

Quote:
Originally Posted by smasher View Post
Search this board for "array shuffle" - I know we've covered it before.
CougarBlitz is offline   Reply With Quote
Old 01-27-2010, 12:42 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

static int button = 0;
static int switchView = 0;

- (IBAction) pushButtonid) sender{
if (button == 0){
if (switchView == 0){

button += 1;
switchView += 1;
AudioServicesPlaySystemSound(pushButtonSound);
box.animationImages = [NSArray arrayWithObjects:

[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
//[UIImage imageNamed:@"Cube09.png"],
//[UIImage imageNamed:@"Cube10.png"],
//[UIImage imageNamed:@"Cube11.png"],
//[UIImage imageNamed:@"Cube12.png"],
//[UIImage imageNamed:@"Cube13.png"],
//[UIImage imageNamed:@"Cube14.png"],
//[UIImage imageNamed:@"Cube15.png"],
//[UIImage imageNamed:@"Cube16.png"],
//[UIImage imageNamed:@"Cube17.png"],
//[UIImage imageNamed:@"Cube18.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Cow On Cube.png"],
nil];

box.animationRepeatCount = 1;
[box setAnimationDuration:1];

[box startAnimating];
[self performSelector:@selector(cow) withObject:nil];
[self performSelector:@selector(animalAppears) withObject:nil afterDelay:.7f];
}
else if (switchView == 1){
button += 1;
switchView += 1;
AudioServicesPlaySystemSound(pushButtonSound);
box.animationImages = [NSArray arrayWithObjects:

[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
//[UIImage imageNamed:@"Cube09.png"],
//[UIImage imageNamed:@"Cube10.png"],
//[UIImage imageNamed:@"Cube11.png"],
//[UIImage imageNamed:@"Cube12.png"],
//[UIImage imageNamed:@"Cube13.png"],
//[UIImage imageNamed:@"Cube14.png"],
//[UIImage imageNamed:@"Cube15.png"],
//[UIImage imageNamed:@"Cube16.png"],
//[UIImage imageNamed:@"Cube17.png"],
//[UIImage imageNamed:@"Cube18.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Horse On Cloud.png"],
nil];

box.animationRepeatCount = 1;
[box setAnimationDuration:1];

[box startAnimating];
[self performSelector:@selector(horse) withObject:nil];
[self performSelector:@selector(animalAppears) withObject:nil afterDelay:.7f];
}
CougarBlitz is offline   Reply With Quote
Old 01-27-2010, 12:44 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

So i have quite a few of these and i need to shuffle them. Any help would be great
CougarBlitz is offline   Reply With Quote
Old 01-27-2010, 12:56 PM   #6 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by CougarBlitz View Post
So i have quite a few of these and i need to shuffle them. Any help would be great
It seems you have a lot of stuff like "button += 1; switchView += 1;" that happens in every case? Then you can move that outside the if statements so you don't have to repeat yourself.

You can also make a master array of arrays, and then choose an array from that by index. Something like this.

Code:
//do this once, maybe in viewDidLoad or initWithNib?

NSArray *cowArray = [NSArray arrayWithObjects:
	[UIImage imageNamed:@"Cube01.png"],
	//etc.
	[UIImage imageNamed:@"Cube19.png"],
	[UIImage imageNamed:@"Cow On Cube.png"],
	nil];


NSArray *horseArray = [NSArray arrayWithObjects:
	[UIImage imageNamed:@"Cube01.png"],
	//etc.
	[UIImage imageNamed:@"Cube19.png"],
	[UIImage imageNamed:@"Cow On Cube.png"],
	nil];

arrayOfImageArrays = [[NSArray alloc] initWithObjects:
	cowArray, horseArray, nil];


//when you need to get the image array
box.animationImages = [arrayOfImageArrays objectAtIndex: switchView];

//if you want a random array from the array of arrays:
int choice = arc4random() % [arrayOfImageArrays count];
box.animationImages = [arrayOfImageArrays objectAtIndex: choice];
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-27-2010, 01:00 PM   #7 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

Thanks that helps a lot. I will work on this. Thank you.
CougarBlitz is offline   Reply With Quote
Old 01-28-2010, 09:44 AM   #8 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default Latest Code, Not running right?

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];

NSArray *arrayOfImageArrays = [[NSArray alloc] initWithObjects:
cowArray, horseArray, gorillaArray, elephantArray, nil];

cowArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
[UIImage imageNamed:@"Cube14.png"],
[UIImage imageNamed:@"Cube15.png"],
[UIImage imageNamed:@"Cube16.png"],
[UIImage imageNamed:@"Cube17.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Cube20.png"],
[UIImage imageNamed:@"Cow On Cube.png"],
nil];

horseArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
[UIImage imageNamed:@"Cube14.png"],
[UIImage imageNamed:@"Cube15.png"],
[UIImage imageNamed:@"Cube16.png"],
[UIImage imageNamed:@"Cube17.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Cube20.png"],
[UIImage imageNamed:@"Horse On Cloud.png"],
nil];

elephantArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
[UIImage imageNamed:@"Cube14.png"],
[UIImage imageNamed:@"Cube15.png"],
[UIImage imageNamed:@"Cube16.png"],
[UIImage imageNamed:@"Cube17.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Cube20.png"],
[UIImage imageNamed:@"Elephant On Cloud.png"],
nil];

gorillaArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
[UIImage imageNamed:@"Cube14.png"],
[UIImage imageNamed:@"Cube15.png"],
[UIImage imageNamed:@"Cube16.png"],
[UIImage imageNamed:@"Cube17.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Cube20.png"],
[UIImage imageNamed:@"Gorilla On Cloud.png"],
nil];



//when you need to get the image array
//box.animationImages = arrayOfImageArrays objectAtIndex: nil];

//if you want a random array from the array of arrays:
int choice = arc4random() % [arrayOfImageArrays count];
box.animationImages = [arrayOfImageArrays objectAtIndex: choice];
CougarBlitz is offline   Reply With Quote
Old 01-28-2010, 10:36 AM   #9 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

(1) you're adding the image arrays to arrayOfImageArrays too soon - you can't add them to arrayOfImageArrays until after they're actually created. Until you create horse array and cow array those variables still point to nil, so you can't add them to arrayOfImageArrays .

(2)Also, arrayOfImageArrays should be in instance variable (declared in the .h file between the brackets of the @interface ) if you need to access it from other methods in this class like the pushButton method.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-28-2010, 11:34 AM   #10 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Question What about repeats? Is there a way to solve this?

I am in the process of trying out the code you suggested but one problem I see is that there doesn't appear to be any way to keep the array from producing repeats. How can I keep this from happening? I don't mind repeats so long as they aren't the same back to back. Thanks in advance!
CougarBlitz is offline   Reply With Quote
Old 01-28-2010, 11:51 AM   #11 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by CougarBlitz View Post
I am in the process of trying out the code you suggested but one problem I see is that there doesn't appear to be any way to keep the array from producing repeats. How can I keep this from happening? I don't mind repeats so long as they aren't the same back to back. Thanks in advance!
Its true arc4random will produce repeats; you can check for them if you make an instance variable "lastChoice" though. Something like this.

Code:
int choice=0;
// keep pulling random numbers until you find
// one that's not equal to lastChoice
while (choice==lastChoice){
     choice = arc4random() % [arrayOfImageArrays count];
}
lastChoice=choice;
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-28-2010, 04:01 PM   #12 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default Keeping last image in animation

Hi thanks for your help it has been fantastic however i have run into one more snag, i must admit i am beginning to feel pretty stupid, but i guess that's part of the learning curve. Anyway if you could help me with one more thing i would be very grateful. I am struggling keeping the last image in the animation on the screen until that sequence has been terminated. So I was wondering if you have any suggestions for this problem. Thanks
CougarBlitz is offline   Reply With Quote
Old 01-28-2010, 04:05 PM   #13 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by CougarBlitz View Post
Hi thanks for your help it has been fantastic however i have run into one more snag, i must admit i am beginning to feel pretty stupid, but i guess that's part of the learning curve. Anyway if you could help me with one more thing i would be very grateful. I am struggling keeping the last image in the animation on the screen until that sequence has been terminated. So I was wondering if you have any suggestions for this problem. Thanks
What's not working? What does it do now after the last frame? I see animationRepeatCount=1 in your code, I though that would do it.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-28-2010, 04:11 PM   #14 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

It is running through the animation fine and at a random. However the method i was using to keep the last frame (Image) on screen untill the animation reset is coming up for each animation. I need to figure out how to set an individual image for the end of each animation frequency. So for instance when I push the button the cow will animate up. well i need the cow to stay up for about 2 seconds so i have an image set for the to happen. then when i push the button again it will come up with the horse for instance, well it keeps the cow image for all the images at the end of the animation. I will show you the code for what i am talking about. I need to be able to call a certain image to come for each animation array. Here let me know if this makes sense.


[self performSelector:@selector(cowArray) withObject:nil];
}

- (void) cowArray{

[box setImage:[UIImage imageNamed:@"Cow On Cube.png"]];
CougarBlitz is offline   Reply With Quote
Old 01-28-2010, 04:15 PM   #15 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

I think what i am trying to do is freeze the last frame for about a second or two. Do you know how i can accomplish this.
CougarBlitz is offline   Reply With Quote
Old 01-28-2010, 04:47 PM   #16 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

This should do it - get the last item in the array (whatever it is) and use that as the image.

Code:
[self performSelector:@selector(freezeLastFrame) withObject:nil];


- (void) freezeLastFrame{

     NSArray *imageArray = box.animationImages;
     box.image = [imageArray lastObject];

     box.animationImages=nil;
}
What happens if you do nothing, though, and just let the animation run out? Does the animation stop on the last frame? I haven't done animationImages in a while so I'm curious.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-28-2010, 04:51 PM   #17 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

I will get back to you on that. I will let you know as soon as i try that.
CougarBlitz is offline   Reply With Quote
Old 01-29-2010, 11:48 AM   #18 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

I am trying to implement the code you gave me however it is coming up with building errors could you send me an example of how you would implement what you told me to do with freezing. Here is some code i have been trying to implement it into. Thanks

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {
[super viewDidLoad];



NSArray *cowArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
[UIImage imageNamed:@"Cube14.png"],
[UIImage imageNamed:@"Cube15.png"],
[UIImage imageNamed:@"Cube16.png"],
[UIImage imageNamed:@"Cube17.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Cube20.png"],
[UIImage imageNamed:@"Cow On Cube.png"]
nil];
CougarBlitz is offline   Reply With Quote
Old 01-29-2010, 12:38 PM   #19 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

I don't see any of the code I wrote in your last post. You said it was freezing OK, just on the wrong image.

Code:
//where you had this before
[self performSelector:@selector(cowArray) withObject:nil];

//you want this now
[self performSelector:@selector(freezeLastFrame) withObject:nil];
Then add my freezeLastFrame method to your class.

EDIT: don't use this, it's not needed. UIImageView seems to show the default .image when it's done playing.
__________________

Free Games!

Last edited by smasher; 01-29-2010 at 01:38 PM.
smasher is offline   Reply With Quote
Old 01-29-2010, 12:59 PM   #20 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

Oh I am sorry i didn't mean that what is happening is the animation is running through the animation fine. But it doesn't keep the last image in the animation up. it basically runs through the animation and then leaves. What i am trying to accomplish is i want the animation to run and then leave the last frame or image up for about 2 to 3 seconds then set back to the image that i put as the default image in interface builder, then the button will get pushed again and the the next animation will begin and do the same thing. I hope this makes better sense. Thanks again for all the help.
CougarBlitz is offline   Reply With Quote
Old 01-29-2010, 01:08 PM   #21 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

I tried writing it out the way you said but it doesn't freeze the last frame. Could you take a look at this and see what you think might be the problem. Thanks

@implementation Animal_CubeViewController

- (IBAction) pushButton{
int lastChoice = 0;
int choice = 0;

// keep pulling random numbers until you find
// one that's not equal to lastChoice

while (choice == lastChoice){
choice = arc4random() % [arrayOfImageArrays count];
}
lastChoice = choice;
box.animationImages = [arrayOfImageArrays objectAtIndex: choice];

box.animationDuration = 1.2f;
box.animationRepeatCount = 1;
[box startAnimating];


[self performSelector:@selector(freezeLastFrame) withObject:nil];
}

- (void) cowArray{

[box setImage:[UIImage imageNamed:@"Cow On Cube.png"]];
}

- (void) freezeLastFrame{
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {
[super viewDidLoad];



NSArray *cowArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
[UIImage imageNamed:@"Cube14.png"],
[UIImage imageNamed:@"Cube15.png"],
[UIImage imageNamed:@"Cube16.png"],
[UIImage imageNamed:@"Cube17.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Cube20.png"],
[UIImage imageNamed:@"Cow On Cube.png"],
nil];



NSArray *horseArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
[UIImage imageNamed:@"Cube14.png"],
[UIImage imageNamed:@"Cube15.png"],
[UIImage imageNamed:@"Cube16.png"],
[UIImage imageNamed:@"Cube17.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Cube20.png"],
[UIImage imageNamed:@"Horse On Cloud.png"],
nil];

NSArray *elephantArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
[UIImage imageNamed:@"Cube14.png"],
[UIImage imageNamed:@"Cube15.png"],
[UIImage imageNamed:@"Cube16.png"],
[UIImage imageNamed:@"Cube17.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Cube20.png"],
[UIImage imageNamed:@"Elephant On Cloud.png"],
nil];

NSArray *gorillaArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Cube01.png"],
[UIImage imageNamed:@"Cube02.png"],
[UIImage imageNamed:@"Cube03.png"],
[UIImage imageNamed:@"Cube04.png"],
[UIImage imageNamed:@"Cube05.png"],
[UIImage imageNamed:@"Cube06.png"],
[UIImage imageNamed:@"Cube07.png"],
[UIImage imageNamed:@"Cube08.png"],
[UIImage imageNamed:@"Cube14.png"],
[UIImage imageNamed:@"Cube15.png"],
[UIImage imageNamed:@"Cube16.png"],
[UIImage imageNamed:@"Cube17.png"],
[UIImage imageNamed:@"Cube19.png"],
[UIImage imageNamed:@"Cube20.png"],
[UIImage imageNamed:@"Gorilla On Cloud.png"],
nil];

arrayOfImageArrays = [[NSArray alloc] initWithObjects:
cowArray, horseArray, gorillaArray, elephantArray, nil];



//when you need to get the image array
//box.animationImages = arrayOfImageArrays objectAtIndex: nil];

//if you want a random array from the array of arrays:

}
CougarBlitz is offline   Reply With Quote
Old 01-29-2010, 01:08 PM   #22 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

I don't think there's any feedback from the system when the animation is complete. I think the best you can do is set a method to fire when you expect the animation to be over.

Code:
[self performSelector:@selector(freezeLastFrame) withObject:nil afterDelay:1];
EDIT: Scratch that. I just did a test, and at the end of the animation the UIImageView showed the image that's in the .image property. So just make sure that box.image is set to the image that you want to show when the animation is over. No tricks required.
__________________

Free Games!

Last edited by smasher; 01-29-2010 at 01:37 PM.
smasher is offline   Reply With Quote
Old 01-29-2010, 03:13 PM   #23 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

That works except for that it now brings up that image for every animation. I need to be able to specify a select image for the end of each array animation. If you look back at my code you will see that i have four different animation going on, and i runs through the animation and then brings up that one select image now that i just coded in. Is there a way i can set an image for each individual array animation, for example. cowArray = set cow pic. horseArray = set horse pic. etc. can you let me know what you think. thanks
CougarBlitz is offline   Reply With Quote
Old 01-29-2010, 03:32 PM   #24 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Sure, set box.image to the last image in the array you chose.

Code:
//if you want a random array from the array of arrays:
int choice = arc4random() % [arrayOfImageArrays count];
box.animationImages = [arrayOfImageArrays objectAtIndex: choice]; 
box.image = [box.animationImages lastObject];
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-29-2010, 04:20 PM   #25 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 43
CougarBlitz is on a distinguished road
Default

Thank You you have been a huge help. It's working like a charm.
CougarBlitz is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, random, randomize

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 322
6 members and 316 guests
2Apps1Day, akacaj, SLIC, soohyun, Techgirl-52, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,114
Posts: 402,886
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:05 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0