これを AppDelegate.h に追加します。
@class CCLayer;
@interface AppController : NSObject <UIApplicationDelegate, CCDirectorDelegate,UIGestureRecognizerDelegate>
{
CCLayer *mCurrentLayer;
}
@property (nonatomic, retain) CCLayer *currentLayer;
これを AppDelegate.mm に追加します。
@implementation AppController
@synthesize currentLayer = mCurrentLayer;
Layer init クラスでこれを使用します。オールシーン方式で。
@implementation MyMainMenu
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
MyMainMenu *layer = [MyMainMenu node];
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
app.currentLayer = layer;
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
プロジェクトのどこでも確認できます。
appDelegate で
-(void) applicationDidEnterBackground:(UIApplication*)application
{
if([self.currentLayer isKindOfClass:[MyMainMenu class]])
MyMainMenu *mm = (MyMainMenu*) self.currentLayer;
[mm calFunction];
}
他のクラスでは:
-(void)callUpdateButtonsInLayer
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
if([app.currentLayer isKindOfClass:[MyMainMenu class]])
{
MyMainMenu *mm = (MyMainMenu*) app.currentLayer;
[mm calFunction];
}
}