Search code examples
objective-ccocos2d-iphone

Start a subclass level from superclass


I'm learning to use Cocos2d for iOS, in particular I am working on an iPhone's app. I created a superclass called basicLevel where i set all I need for every level I'm going to create. Of course, the levels I'm going to create will be subclasses of basicLevel. In basicLevel there is a CCMenu that contains a CCMenuItemImage called startButton. What I want to do is that when I touch that button the subclass level start. For example in the first level I'm creating, there is a timer and I want that this timer start only when startButton is touched.

Thank you.


Solution

  • Create a method in the base class (basicLevel) that is called whenever the menu button you want is pressed:

    - (void)startLevel;
    

    Then override this method on all classes that derive from basicLevel.