cristianbote/phaser-state-transition

Misplaced sprites and groups after state transition

JarLowrey opened this issue · 5 comments

Referencing the conversation started here #16 (comment) I discovered the issue was somehow related to group's top/bottom properties breaking when using state transitions. You can see the commit with the workaround here.

state transitions are working, turns out some_group.top/bottom is somehow broken due to them. If you use some_group.y to set y position instead it will work. To test this, run the current code with state transitions: it works. Then, set groupTopAndBottomPropertiesAreMessedUp on line 73 of the Store state to false. After a few Store>Game>Store transitions the Store state will break (because top/bottom properties are used). Finally remove state transitions by going to the Preload state, commenting out line 13 (the import), line 40, and line 44 (state transition getters). Uncomment lines 39 and 43 (now they are state.start parameter functions). Set groupTopAndBottomPropertiesAreMessedUp to true or false, they both work.

Hey,

Thanks for creating a new issue for it!
So, looking over your code, and then over Phaser's Group prototype for.top (https://github.com/photonstorm/phaser/blob/master/src/core/Group.js#L2771) seems like it might be actually related to Phaser setter of .top. Check it out, there's a call to .getBounds() after which the group's .y is being set.
IMO it's randomly happening, maybe, because whenever the transition didn't finished yet, and the slide it's still animating, the .top setter makes the call to .getBounds() which in turn might catch the overlapping of the slide.

To confirm this, can you use this instead of getRandomStateTransitionIn()

{
    ease: Phaser.Easing.Exponential.InOut,
    duration: 2e3, // 2s
    intro: true,
    props: {
        y: function(game) {
            return game.height;
        }
    }
}

This increases the transition duration and you could notice the scrambled sprites more often.

Cheers!

Ah ok i thought it might be something like this. That seems probable to me. I'll check it out after work. Thanks man! Good find!

Yeah that change makes it much more likely. I upped it to 3s and it seems to happen every time. commit Can you clarify what you mean by

.top setter makes the call to .getBounds() which in turn might catch the overlapping of the slide.

Any idea on how we can remedy this? I'm looking over the plugin now for potential solutions. I've updated my repo with the new transitions. Something suspicious that I've noticed is that on the initial rendering game.world has the properties

//on my monitor
centerX:586
centerY:409
x:-0
y:-0

but on all subsequent state transitions when it breaks (remains the same when it does not break):

centerX:586
centerY:-2551
x:-0
y:-0

Since I'm only transitioning on Y, I'd assume game.world would probably break on its X value when you transition horizontally as well.

Also, I noticed some other potential issues.

  1. When my random 'out' transition is null and the 'in' transition is In.SlideTop, no transitions occur. When 'in' is null and 'out' is Out.SlideTop, transitions work.
  2. When the 'out' transition is Out.SlideTop and the 'in' transition is the custom one defined above, it transitions in a disjointed way.
  • store transitions out via SlideTop. It appears that the next state begins simultaneous to the transition, which means by the time it finishes the state has been running game logic for a little while.
  • There is a brief pause as you can see the next state running.
  • The 'In' transition begins & ends, overlapping game state, and you can view the state again.

K I've fixed some issues but still have not figured out why world/Groups are getting messed up. It seems to somehow be caused by the renderXY call that is drawing world to the ContentSnapshot Image

OK SO I found a work around. Instead of using ...renderXY(game.world... iterate over all of game.world's children and call renderXY on those instead. I guess game.world is treated different than a generic Phaser.Group or displayObject. But this seems to work well for me! I'll submit a PR.