2

I'm trying to update my project to Cocos2d v3. I wonder how to implement update method which runs every frame. Here https://www.makegameswith.us/gamernews/359/cocos2d-30-a-brief-transition-guide there is info that no [self scheduleUpdate]; call is required, just to add method

- (void)update:(CCTime)delta {
       ...
}

As I guess this method will run every frame when scene loads. But what if I want to start schedule after some other event? button press for example, or start, then stop and then rerun it again?

Also what about ccTime? it is simply renamed to CCTime?

James Webster
  • 31,873
  • 11
  • 70
  • 114
Grixol
  • 63
  • 5

1 Answers1

2

Yes, the update method is run every frame.

If you want to have different behaviour according to your game states that you can simply use if or switch, especially if your game is simple.

If it is more complicated you can always choose a different method to run.

Here is my selector property

// The update selector used depending on state
@property (nonatomic, assign) SEL updateSelector;

And my update method

- (void) update:(CCTime)delta
{
    if (self.updateSelector != nil)
    {
        IMP imp = [self methodForSelector:self.updateSelector];
        void (*func)(id, SEL) = (void *)imp;
        func(self, self.updateSelector);
    }
}

And I set the different update selector depending on my state.

Tibor Udvari
  • 2,932
  • 3
  • 23
  • 39