01-27-2011, 01:12 PM
#1 (permalink )
Registered Member
Join Date: Jul 2008
Posts: 55
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.
01-27-2011, 01:19 PM
#2 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
An array doesn't start, so I not understand what you mean, just check your index, and if ==X use the 2nd array
__________________
01-27-2011, 01:23 PM
#3 (permalink )
Registered Member
Join Date: Jul 2008
Posts: 55
Quote:
Originally Posted by
dany88
An array doesn't start, so I not understand what you mean, just check your index, and if ==X use the 2nd array
-(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.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?
01-27-2011, 01:34 PM
#4 (permalink )
Registered Member
Join Date: Jul 2008
Posts: 55
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)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.animationDuration = 1;
[stick startAnimating];
}
-(IBAction)stopClick
id)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 .
01-27-2011, 01:40 PM
#5 (permalink )
Registered Member
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
Use a case statement depending on what image is selected to decrease the duration?
01-27-2011, 01:43 PM
#6 (permalink )
Registered Member
Join Date: Jul 2008
Posts: 55
Quote:
Originally Posted by
Brandt
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?
01-27-2011, 01:46 PM
#7 (permalink )
Registered Member
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
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 .
01-27-2011, 01:54 PM
#8 (permalink )
Registered Member
Join Date: Jul 2008
Posts: 55
Quote:
Originally Posted by
Brandt
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
01-27-2011, 02:00 PM
#9 (permalink )
Registered Member
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
Read the
NSArray Class Reference
You should probably use the objectAtIndex...Index numbers in an array start at 0.
01-27-2011, 02:14 PM
#10 (permalink )
Registered Member
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
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
01-27-2011, 04:16 PM
#11 (permalink )
Registered Member
Join Date: Jul 2008
Posts: 55
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;
}
}#
01-27-2011, 04:30 PM
#12 (permalink )
Registered Member
Join Date: Jul 2008
Posts: 55
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)Faster
id)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)
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
Quote:
Originally Posted by
aa233
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)Faster
id)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
01-27-2011, 06:08 PM
#14 (permalink )
Registered Member
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
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
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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