objective-ccocos2d-iphonecclayer

How transition between layers in cocos2d?


I have a menu scene hierarchy like so:

Scene
   |
Background Layer
   |           |
Main Menu    Settings Menu

I want to transition from the Main Menu to the Settings Menu without moving the Background Layer. There is plenty of documentation on how to transition between scenes, but nothing that I can find between layers. Both the Main Menu and Settings Menu layer are full screen with transparent backgrounds, I just want to slide in between them without moving the background.

Simple problem, but I am totally stumped after searching the web for over an hour.


Solution

  • Have a node which Main Menu is a child of. Add Settings Menu to this node with an offset of +screenWidth or -screenWidth depending on the direction desired. Then create a sequence of a CCMoveTo where you move your node to the other side of the screen (or off screen if going backwards) followed by a CCCallFunc which calls a function to remove the Main Menu layer from the main node. This will work equally well for vertical transitions (just use screenHeight and move the node vertically).