开发者

Cocos2d: Calling function from one CCLayer in another (parent?) CCLayer

Hello awesome dev community. I have looked for an answer to this for days now and just can't seem to find a handle, so decided to post Q myself.

I have a game that has menus for picking items. The menus can have 2 -> 30+ items, so they need to scroll. There are also category menus, which when an item is clicked, a new menu with that category's items appears.

开发者_如何学CI figured that the most efficient way to go about it is by creating all the elements needed for the menu on a dedicated layer. The issue is that I have no idea how to call my addNewItems:itemsArray function defined in the main game scene, from the CCLayer containing the menu.

Or, should I just use one layer? A bit messy and difficult to move multiple items together.

Thank you so much for any help - or pointing me in the direction of a clear tutorial or examples of how to do that since I honestly couldn't find any.

Below is a flowchart of what I'm looking to create.

Thanks!!

Hanaan

Cocos2d: Calling function from one CCLayer in another (parent?) CCLayer


Finally got an answer from David994A (cocos2d forum)

The answer is to pass the layer a pointer to it's parent layer I initialize the CCLayer like this:

-(id) initWithParent:(CCLayer *)parentLayer;

and call it like this:

ItemsMenuLayer *tempLayer = [[ItemsMenuLayer alloc] initWithParent:self];

Then, from inside the CClayer I can call any of the parent's layer functions, like this:

[parentLayer functionName];

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜