3

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.

rnystrom
  • 1,906
  • 2
  • 21
  • 47
  • Why not do this with scenes as it was intended to be? No point in making things more complicated than necessary. You might also want to look into push and pop scenes if persisting state (with no additional code) is important to you. – CodeSmile Dec 06 '11 at 21:28
  • From what I've seen I can't have a persistent background. I'm talking about the background staying put, no animation (even if the new scene IS the same background, I don't want it to move). – rnystrom Dec 06 '11 at 21:47
  • The background won't move if you don't use transitions. To transition layers, simply load both layers and run actions like CCMoveTo on each layer simultaneously to move them in and out., – CodeSmile Dec 07 '11 at 10:45

1 Answers1

2

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).

jrtc27
  • 8,496
  • 3
  • 36
  • 68
  • I'll play with this when I get home, looks promising. When you say "node", are you saying just use a CCNode or the node of a CCLayer? – rnystrom Dec 06 '11 at 21:48
  • 1
    Use a CCNode (`CCNode *container = [CCNode node];` although you will probably be setting a pointer in your header rather than a new one). – jrtc27 Dec 06 '11 at 22:32
  • You nailed it. Set up a custom menu manager that puts menus in a node and animates them in and out of the scene just how I wanted. Thanks! – rnystrom Dec 07 '11 at 02:42