Question

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.

I 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

alt text

Was it helpful?

Solution

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];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top