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-2011, 01:12 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 55
aa233 is an unknown quantity at this point
Default Array Question

Hello,
I am trying to figure out how to make an array start when another one stops on a certain image. So for example say I have three images in the first array, if the user stops the array and it lands on image 2, i want this to trigger another array. However, if a user stops the first array on image 1, the first array continues to play while the second one does not. Is there anyway I can do this? Thank you.
aa233 is offline   Reply With Quote
Old 01-27-2011, 01:19 PM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

An array doesn't start, so I not understand what you mean, just check your index, and if ==X use the 2nd array
__________________
dany_dev is offline   Reply With Quote
Old 01-27-2011, 01:23 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 55
aa233 is an unknown quantity at this point
Default

Quote:
Originally Posted by dany88 View Post
An array doesn't start, so I not understand what you mean, just check your index, and if ==X use the 2nd array
-(IBAction)startClickid)sender {
stick.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"red enemy.png"],
[UIImage imageNamed:@"yellow goal.png"],
[UIImage imageNamed:@"blue user.png"],nil];
[stick setAnimationRepeatCount:0];
stick.animationDuration = 1;
[stick startAnimating];
}

The button attached to startClick starts the array. I also have a button that stops the array. My question is, how would I make the array go faster after the user stops the array on a certain image?
aa233 is offline   Reply With Quote
Old 01-27-2011, 01:34 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 55
aa233 is an unknown quantity at this point
Default Does anybody understand what I'm even asking for?

Does anybody understand what I'm even asking for? This is what I have so far but I keep getting an error saying "expected identifier or "{" before 'if'

-(IBAction)startClickid)sender {
stick.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"red enemy.png"],
[UIImage imageNamed:@"yellow goal.png"],
[UIImage imageNamed:@"blue user.png"],nil];
[stick setAnimationRepeatCount:0];
stick.animationDuration = 1;
[stick startAnimating];
}
-(IBAction)stopClickid)sender {
stick.animationImages = nil;
}
if ((stopClick == TRUE) && (stick.animationImages = UIImage imageNamed:@"yellow goal.png")) {
stick.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"red enemy.png"],
[UIImage imageNamed:@"yellow goal.png"],
[UIImage imageNamed:@"blue user.png"],nil];
[stick setAnimationRepeatCount:0];
stick.animationDuration = .5;
[stick startAnimating];
}

Last edited by aa233; 01-27-2011 at 01:38 PM.
aa233 is offline   Reply With Quote
Old 01-27-2011, 01:40 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
Brandt is on a distinguished road
Default

Use a case statement depending on what image is selected to decrease the duration?
Brandt is offline   Reply With Quote
Old 01-27-2011, 01:43 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 55
aa233 is an unknown quantity at this point
Default

Quote:
Originally Posted by Brandt View Post
Use a case statement depending on what image is selected to decrease the duration?
So by including a case statement, if the user clicks the stop button on a certain image, teh array will speed up?
aa233 is offline   Reply With Quote
Old 01-27-2011, 01:46 PM   #7 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
Brandt is on a distinguished road
Default

Please use the code (#) tags. Try not to mix dot notation and blocked notation. Synthesizing automatically creates the setters and getters for you.

Code:
-(IBAction)startClick: (id)sender {
    stick.animationImages = [NSArray arrayWithObjects:
                                               [UIImage imageNamed:@"red enemy.png"],
                                               [UIImage imageNamed:@"yellow goal.png"],
                                               [UIImage imageNamed:@"blue user.png"],
                                               nil];
    [stick setAnimationRepeatCount:0];
    [stick setAnimationDuration:1];
    [stick startAnimating];
}

-(IBAction)stopClick: (id)sender {
    [stick setAnimationImages: nil];

    if ((stopClick == TRUE) && (stick.animationImages =                                
                                         UIImage imageNamed:@"yellow goal.png")) 
    {
        stick.animationImages = [NSArray arrayWithObjects:
        [UIImage imageNamed:@"red enemy.png"],
        [UIImage imageNamed:@"yellow goal.png"],
        [UIImage imageNamed:@"blue user.png"],nil];
        [stick setAnimationRepeatCount:0];
        [stick setAnimationDuration:0.5];
        [stick startAnimating];
    }
}

Now that your code is more readable let's look at it.


-You should be referring to your image by index number not by image name

Last edited by Brandt; 01-27-2011 at 01:48 PM.
Brandt is offline   Reply With Quote
Old 01-27-2011, 01:54 PM   #8 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 55
aa233 is an unknown quantity at this point
Default

Quote:
Originally Posted by Brandt View Post
Please use the code (#) tags. Try not to mix dot notation and blocked notation. Synthesizing automatically creates the setters and getters for you.

Code:
-(IBAction)startClick: (id)sender {
    stick.animationImages = [NSArray arrayWithObjects:
                                               [UIImage imageNamed:@"red enemy.png"],
                                               [UIImage imageNamed:@"yellow goal.png"],
                                               [UIImage imageNamed:@"blue user.png"],
                                               nil];
    [stick setAnimationRepeatCount:0];
    [stick setAnimationDuration:1];
    [stick startAnimating];
}

-(IBAction)stopClick: (id)sender {
    [stick setAnimationImages: nil];

    if ((stopClick == TRUE) && (stick.animationImages =                                
                                         UIImage imageNamed:@"yellow goal.png")) 
    {
        stick.animationImages = [NSArray arrayWithObjects:
        [UIImage imageNamed:@"red enemy.png"],
        [UIImage imageNamed:@"yellow goal.png"],
        [UIImage imageNamed:@"blue user.png"],nil];
        [stick setAnimationRepeatCount:0];
        [stick setAnimationDuration:0.5];
        [stick startAnimating];
    }
}

Now that your code is more readable let's look at it.


-You should be referring to your image by index number not by image name
Firstly, thanks for the tip on posting the code, I've been trying to figure that out. Secondly, I'm a novice at programming so i'm not exactly sure if an index number is automatically generated or not. What would i need to do if all i wanted was to speed up the array every time the user clicks stop when the array is on the "yellow goal"?
Thanks for your patience by the way
aa233 is offline   Reply With Quote
Old 01-27-2011, 02:00 PM   #9 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
Brandt is on a distinguished road
Default

Read the NSArray Class Reference


You should probably use the objectAtIndex...Index numbers in an array start at 0.
Brandt is offline   Reply With Quote
Old 01-27-2011, 02:14 PM   #10 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
Brandt is on a distinguished road
Default

Also, don't reinstantiate the array every time a button is pushed...it looks like a static array so NSArray is correct, but declare it in your header file and define it in your implementation file so it is available to all your methods
Brandt is offline   Reply With Quote
Old 01-27-2011, 04:16 PM   #11 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 55
aa233 is an unknown quantity at this point
Default

In my game I have an animation via an array, and every time the user clicks a button, if the array is on a certain image, i want the array to start over and speed up. Here is what I have so far. I keep getting an error saying "expected expression before 'UIImage'" Sorry I needed to clarify myself. What's wrong with this code?


#-(IBAction)startClickid)sender {
stick.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"red enemy.png"],
[UIImage imageNamed:@"yellow goal.png"],
[UIImage imageNamed:@"blue user.png"],nil];
[stick setAnimationRepeatCount:0];
stick.animationDuration = 1;
[stick startAnimating];
}


- (IBAction)Fasterid)sender {
if (UIImage = @"yellow goal.png") {
stick.animationDuration = .5;
}
}#
aa233 is offline   Reply With Quote
Old 01-27-2011, 04:30 PM   #12 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 55
aa233 is an unknown quantity at this point
Default

I keep toying around and cannot do anything about this error message. I'm guessing its something small but I can't figure out what. This is the updated code:

- (IBAction)Fasterid)sender {
if (UIImage = [@"yellow goal.png"] {
stick.animationDuration = .5;
else {
stick.animationDuration = 1;
}

}
}
The error messages now say expected expression before 'UIImage' and expected expression before '}' token (in reference to the third bracket)
aa233 is offline   Reply With Quote
Old 01-27-2011, 04:37 PM   #13 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

Quote:
Originally Posted by aa233 View Post
I keep toying around and cannot do anything about this error message. I'm guessing its something small but I can't figure out what. This is the updated code:

- (IBAction)Fasterid)sender {
if (UIImage = [@"yellow goal.png"] {
stick.animationDuration = .5;
else {
stick.animationDuration = 1;
}

}
}
The error messages now say expected expression before 'UIImage' and expected expression before '}' token (in reference to the third bracket)
The symptom is small, but the issue is much larger. Start here:

Objective-C Introduction
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 01-27-2011, 06:08 PM   #14 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
Brandt is on a distinguished road
Default

Please use the code tags, it is the hash button on the rich text editor.

or manually
[ C O D E ]

[ / C O D E ]

remove the spaces



define the array in viewDidLoad or viewWillLoad
Brandt is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, nsarray

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: 355
14 members and 341 guests
7twenty7, Clouds, dre, EvilElf, iAppDeveloper, jeroenkeij, jimmyon122, Mah6447, Morrisone, n00b, pungs, Sami Gh, stanny, toon4413
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,121
Posts: 402,899
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

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