Author Topic: Objects disappearing with FlxState changes?  (Read 859 times)


  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Objects disappearing with FlxState changes?
« on: Thu, Mar 17, 2011 »
So i'm fairly new to flixel and flash in general and have started trying to make a simple platformer game.

In this game i have different "scenes" as opposed to moving the screen continually as you walk. As in when the player reaches the edge of the screen the screen changes to the next section which the player can walk through again.

My problem is everyone works fine when the player walked off the right of the screen and the new scene if created, however when the player walks off the left of the screen and back into the previous scene all the objects that were previously rendered (like the player and the tilemap) is no longer shown.

I am changing "scenes" by changing FlxG.state to the scene i want to show and i'm retaining "scenes" by passing itself to the newly created scene and saving a pointer to the new scene each time. Basically keeping a bi-directional linked list structure of scenes.

Also every "scene" has it's own tilemap and player sprite. And the player at least still exists as i constantly print out the players location.

Any idea why they aren't showing when going back?


  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Objects disappearing with FlxState changes?
« Reply #1 on: Thu, Mar 17, 2011 »
When the state is changed it'll call destroy on anything within it. For most objects destroy is an empty method meant for you to override and populate. But for FlxGroups it does nuke all group members - and as a State basically is one giant Group my guess would be that it has set its members to "not exist", so regardless what reference you may have to the State all of the members have been told they don't exist any more, so the render/update skips them.

If there's a way to achieve what you need *without* changing State, then I'd explore that. Otherwise you need to extend State to include some kind of "restore members" method (or alternatively remove the destroy calls)

"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius