开发者

Reflection doesn't work for CCScene, why?

I have a sub-class of CCLayer, named MyScene. In the App Delegate I added this code:

-(void) applicationDidEnterBackground:(UIApplication*)ap开发者_C百科plication {
    [[CCDirector sharedDirector] stopAnimation];

    if( [[CCDirector sharedDirector] runningScene] != nil ) {
        if( [[[CCDirector sharedDirector] runningScene] isKindOfClass:[MyScene class]] ) {
            MyScene *scene = (MyScene*) [[CCDirector sharedDirector] runningScene];
            [scene goingToBackground];
    }
}

}

The app has a running scene, and I know it's MyScene, but isKindOfClass doesn't return YES. Why?


[[CCDirector sharedDirector] runningScene] always returns a CCScene not a CCLayer object. As you are comparing a CCScene with your CCLayer sub class i.e. MyScene so it always return false. Try to set the tag of your MyScene object and get that object by tag and the compare it. it will return YES

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜