Jump to content

How state change affects World


denisb
 Share

Recommended Posts

Lets say I create 2 states, stateA and stateB. I start stateA which creates a sprite object and adds it to the World. Then I start stateB, assign the sprite object that was created in StateA and added to World, to a variable in stateB. Will I not be able to access the sprite because it was destroyed when I changed states? Do I need to create another sprite and add it to the World?

 

Link to comment
Share on other sites

When starting State, there are two optional parameters:

start: function (key, clearWorld, clearCache)

clearWorld is set to true by default. It means your sprite in stateA will be destroyed. If you set it to false then world and all objects in it will be preserved.

Imagine world as scene graph - tree like structure, where tree is made from sprites, groups, text objects, etc. Clearing world means, that world tree is traversed and objects are destroyed. So, if you want to preserve only part of it, like single sprite, you have first disconnect it from tree (like calling remove on parent), then change state to stateB and then connect it back to tree (with calling add on parent).

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...