NSArray Animation Problem....

Discussion in 'iOS Programming' started by TrentS, Jul 1, 2014.

  1. TrentS macrumors 6502

    TrentS

    Joined:
    Sep 24, 2011
    Location:
    Overland Park, Kansas
    #1
    I have an NSArray animation in my game app that basically is implemented whenever a certain button is pushed, but I would rather have the animation begin when my game is first initializes. To begin the game, the player only has to tap the screen. Is there anywhere I can find out how to make my animation not dependant on said button, but rather just begin on game start up? It seems like all the video tutorials hinge on animation initialization with a connecting button. Any help would be greatly appreaciated. Thanks!

    :) :) :) :)
     
  2. JohnsonK, Jul 1, 2014
    Last edited: Jul 1, 2014

    JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #2
    NSArray animation?

    You did not provide any details or code, so I can't give a better answer. You have to move your code from your button to viewWillAppear, viewDidAppear or equivalent.

    Did you make the game or downloaded it from somewhere?
     
  3. TrentS thread starter macrumors 6502

    TrentS

    Joined:
    Sep 24, 2011
    Location:
    Overland Park, Kansas
    #3
    Sweet!

    Yes, you are right. I am sorry. I will try and add the code when I get home tonight. It is my first attempt at making an xcode game app ( or any app for that matter ). I have learned quite a bit in about a months time, and I am amazed out how much I am loving it. When I finally write something and it works - Sweet!

    I just need to figure out when to stop and call it complete. I seem to keep adding more and more features as I go. I only have a few snags that I need to iron out, then I will join the Dev. program and submit my game soon after. It is exciting!

    :) :) :) :)
     
  4. TrentS, Jul 2, 2014
    Last edited by a moderator: Jul 2, 2014

    TrentS thread starter macrumors 6502

    TrentS

    Joined:
    Sep 24, 2011
    Location:
    Overland Park, Kansas
    #4
    Code....

    Okay, here is the code.....


    Under .h I have...


    Code:
    IBOutlet UIImageView *animateImage;
    
    -(IBAction)startAnimating;






    Under .m I have...


    Code:
    @implementation ViewController
    
    
    
    
    
    
    
      -(IBAction)startAnimating {
    
         animateImage.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"Scuba1.png"], [UIImage imageNamed:@"Scuba2.png"],
    
              [UIImage imageNamed:@"Scuba3.png"], nil];
    
       [animateImage setAnimationRepeatCount:0];
    
        animateImage.animationDuration = 0.95;
    
        [animateImage startAnimating];
    
    
    
    
      }



    Right now, in order for the animation to start, the player has to tap a button ( that is just the way the tutorial had me set it up ). My game is set up to start when the player taps anywhere on the screen. I would like for my animations to start playing at that moment, instead of a button. Or they could even start when the player first opens up the app, I just wouldn't want their "movement" on the screen to start until the player taps the screen. I've tried numerous things, like moving the code under "touchesBegan" and viewDidLoad", but nothing seems to work..... Is there another tutorial I can watch, or is this so simple and I'm just missing something?

    :confused: :confused: :confused: :confused:
     
  5. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #5
    I might be wrong here but I would try you code in the viewWillAppear delegate method. But if memory serves me right the objects for the view are not yet initialized before viewDidLoad is called. By the time the viewWillAppear is called the objects are initialized and it should work. I ran in to this kind of problem last year and it drove me nuts. I think that was the solution.
     
  6. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #6
    It is animating for less than a second, too fast. Try viewDidAppear

    PS: I suggest you to stop for a moment and begin learning the basics of programming languages before actually trying to follow a complex tutorial.
     

Share This Page