开发者

Call method from multiple controllers

I know there's an easy answer to this out there but I sure haven't been able to execute it correctly.

I'm making a game where I have a controller for every level. When you beat a level, I want a method that will load and show the next level, i.e. the next controller. I want to be able to use this same method from every contr开发者_如何学运维oller.

My question is where do I create the method and how do I call it?

I've tried delegates, putting the method in the application controller, etc. I just can't figure this one out.


RoorViewContoroller or just root controller is what you need. I'm working on game, too, I'm using Cocos2d-iphone game engine. I'll show you how it works there. There's one common class, implemented as a Singleton, called ССDirector. It is a root controller by instance.

//AppDelegate.m (entry point)
//I run first scene from AppDelegate
[[CCDirector sharedDirector] runWithScene: [MainMenu scene]];
....
//MainMenu.m
//I change scene from Menu to Game Level

- (void) runLevel: (int)level withTheme: (int)themeNo
{
...
    Class GameClass;         //I can run different levels
...
    [[CCDirector sharedDirector] replaceScene:[GameClass scene]];
}

Internally, CCDirector releases current controller (MainMenu) and retains just created (GameClass scene).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜