Multi-scene switching life cycle in Cocos2d-x Lua

Source: Internet
Author: User

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
  1. function Settingscene:ctor ()
  2. -- self.visiblesize = cc. Director:getinstance (): Getvisiblesize ()
  3. Cclog ("Settingscene init")
  4. --Scene node event handling
  5. Local function onnodeevent (event)
  6. If event = = "Enter" Then
  7. Self:onenter ()
  8. ElseIf Event = = "Entertransitionfinish" Then
  9. Self:onentertransitionfinish ()
  10. ElseIf Event = = "Exit" Then
  11. Self:onexit ()
  12. ElseIf Event = = "Exittransitionstart" Then
  13. Self:onexittransitionstart ()
  14. ElseIf Event = = "Cleanup" Then
  15. Self:cleanup ()
  16. End
  17. End
  18. Self:registerscripthandler (onnodeevent)
  19. End
  20. function Settingscene:onenter ()
  21. Cclog ("Settingscene onEnter")
  22. End
  23. function Settingscene:onentertransitionfinish ()
  24. Cclog ("Settingscene onentertransitionfinish")
  25. End
  26. function Settingscene:onexit ()
  27. Cclog ("Settingscene onExit")
  28. End
  29. function Settingscene:onexittransitionstart ()
  30. Cclog ("Settingscene Onexittransitionstart")
  31. End
  32. function Settingscene:cleanup ()
  33. Cclog ("Settingscene cleanup")
  34. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.