Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Array Question

aa233aa233 Posts: 55Registered Users
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.
Post edited by aa233 on

Replies

  • dany_devdany_dev Posts: 4,700Tutorial Authors, Registered Users
    An array doesn't start, so I not understand what you mean, just check your index, and if ==X use the 2nd array
  • aa233aa233 Posts: 55Registered Users
    dany88;294169 said:
    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?
  • aa233aa233 Posts: 55Registered Users
    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];
    }
  • BrandtBrandt Posts: 277Registered Users
  • aa233aa233 Posts: 55Registered Users
    Brandt;294180 said:
    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?
  • BrandtBrandt Posts: 277Registered Users
    Please use the code (#) tags. Try not to mix dot notation and blocked notation. Synthesizing automatically creates the setters and getters for you.


    -(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
  • aa233aa233 Posts: 55Registered Users
    Brandt;294186 said:
    Please use the code (#) tags. Try not to mix dot notation and blocked notation. Synthesizing automatically creates the setters and getters for you.


    -(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
  • BrandtBrandt Posts: 277Registered Users
  • BrandtBrandt Posts: 277Registered Users
    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
  • aa233aa233 Posts: 55Registered Users
    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;
    }
    }#
  • aa233aa233 Posts: 55Registered Users
    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)
  • dljefferydljeffery Posts: 1,311iPhone Dev SDK Supporter, Registered Users
    aa233;294260 said:
    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
    Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

    Recall It! for iPad
  • BrandtBrandt Posts: 277Registered Users
    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
Sign In or Register to comment.