multi-scene switching life cycle in Cocos2d-x Lua
The life cycle of a scene is more complex when multiple scenes are switched. In this section we describe the scene switching life cycle.
There are several scenarios when switching multiple scenes:
In case 1, use the Pushscene function to enter the Settingscene scene from the implementation of the Gamescene scene.
In case 2, use the Replacescene function to enter the Settingscene scene from the gamescene scene.
In case 3, use the Popscene function to return to the gamescene scene from the implementation of the Settingscene scene.
We refer to Gamescene to rewrite several life-cycle functions in Settingscene, the code is as follows:
[HTML]View Plaincopy
- function Settingscene:ctor ()
- -- self.visiblesize = cc. Director:getinstance (): Getvisiblesize ()
- Cclog ("Settingscene init")
- --Scene node event handling
- Local function onnodeevent (event)
- If event = = "Enter" Then
- Self:onenter ()
- ElseIf Event = = "Entertransitionfinish" Then
- Self:onentertransitionfinish ()
- ElseIf Event = = "Exit" Then
- Self:onexit ()
- ElseIf Event = = "Exittransitionstart" Then
- Self:onexittransitionstart ()
- ElseIf Event = = "Cleanup" Then
- Self:cleanup ()
- End
- End
- Self:registerscripthandler (onnodeevent)
- End
- function Settingscene:onenter ()
- Cclog ("Settingscene onEnter")
- End
- function Settingscene:onentertransitionfinish ()
- Cclog ("Settingscene onentertransitionfinish")
- End
- function Settingscene:onexit ()
- Cclog ("Settingscene onExit")
- End
- function Settingscene:onexittransitionstart ()
- Cclog ("Settingscene Onexittransitionstart")
- End
- function Settingscene:cleanup ()
- Cclog ("Settingscene cleanup")
- End
1. In case 1, it is called in order.
Scenario 1 life cycle event sequence
2, in the case of 2, it is called in the order shown, the visible and figure 6-8 is different from the Gamescene cleanup event, which also shows that the Replacescene function will release the scene object.
Life cycle Event Sequence
3, in case 3, it is called in the order shown, the visible popscene function when the Settingscene cleanup event is triggered, indicating that the Popscene function will release the Settingscene scene object, When returning to the gamescene scene, the Init event is not triggered, but the Enter event is triggered.
Scenario 3 life cycle event sequence
Multi-scene switching life cycle in Cocos2d-x Lua