architecturecocos2d-iphonesubclassprogram-structure

Should I not be subclassing the Cocos2d CCDirector class?


I'm trying to make cocos2d work as an RPG engine. I'm thinking of making a class that will coordinate the movements of the characters, the map loading/unloading etc. Should I make a CCNode for this, or just extend the CCDirector? Is there a reason not to subclass the CCDirector?


Solution

  • I have never seen a subclass of CCDirector except the subclasses in cocos2d (CCDirectorDisplayLink, CCDirectorTimer or so on). Subclasses of CCDirector are allowed to create, but it is not really needed.

    If you want a method that is invoked for every frame, you can use CCScheduler -scheduleSelector:forTarget:interval:paused: method. It will invoke the selector for every frame from the main loop.

    [[CCScheduler sharedScheduler]
        scheduleSelector:@selector(tick:) forTarget:self interval:0 paused:NO];
    

    And CCScene is able to use for loading/unloading resource data, or etc.

    Also, how about these tutorials?