开发者

Cocos2D : is it possible to access the iVar in the cclayer , which is declared in scene

开发者 https://www.devze.com 2023-02-10 19:12 出处:网络
I am pretty to cocos2D. i am working in a small game which has a one scene which is called intro scene. the intro scene has 3 lay开发者_运维问答ers.I declared some variables in scene and i want to use

I am pretty to cocos2D. i am working in a small game which has a one scene which is called intro scene. the intro scene has 3 lay开发者_运维问答ers.I declared some variables in scene and i want to use it in layers which is child to the intro scene. In oops there is way to access the parent variable in child. but i struggled how to inherit the variables . is there any access specifier to limit the variable scope. Provide some example and explanation.

Thanks


How about this?

YourScene *parentScene = (YourScene *)self.parent;
/* access some variables in the scene from child layer */


YourScene *parentScene = (YourScene*)self.parent;

/* access some variables in the scene from child layer */

I follow the above code to access the instance variable declared in scene.for instance i did the changes in my code but i doesn,t work.

CCTMXTileMap *tileMap=(CCTMXTiledMap *) parentScene.tTileMap;

where tTileMap declared and added into the scene ;

how to access the variable (declared in parent scene) in Layer as a child to the parent Scene.

0

精彩评论

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