2

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

Hanaan Rosenthal
  • 1,359
  • 1
  • 11
  • 20

1 Answers1

5

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

Hanaan Rosenthal
  • 1,359
  • 1
  • 11
  • 20
  • 1
    But where do you put those exactly? Could you post a .h and .m example? – Chewie The Chorkie May 05 '11 at 17:01
  • Sorry for the late reply to this... The initWithParent is the init method of the layer The ItemsMenuLayer *tempLayer = [[ItemsMenuLayer alloc] initWithParent:self]; line is creating an instant of the layer in the scene. In any of the layer's methods you can call a function from the parent with: [parentLayer functionName]; – Hanaan Rosenthal Dec 14 '11 at 18:30