excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.81k stars 188 forks source link

Scene transitions may not start in correct state when fixedUpdateFps is set #2969

Open mattjennings opened 7 months ago

mattjennings commented 7 months ago

https://github.com/excaliburjs/Excalibur/assets/8703090/8557ea64-fabd-4805-8158-f3d2bee210a4

It seems that the first frame of a scene transition may be incorrect when fixedUpdateFps is set to a rate lower than the screen refresh rate. To exaggerate the effect, I've set the fixedUpdateFps to 5 in the video, but it's occasionally noticeable when set to 60fps on a 120hz screen.

It occasionally does something similar on the final frame as well, where it'll flicker back to the beginning of the transition.

Steps to Reproduce

https://jsfiddle.net/mattjennings/mkL637pz/2/

Expected Result

Should not see a flicker on first frame of transition

Actual Result

It flickers on the first frame

Environment

eonarheim commented 7 months ago

Ack! Good find, fixed update strikes again!

eonarheim commented 7 months ago

I've done a little poking around, I think there are multiple things going on.

During the fixed update

  1. The camera is not updating the position transform after scene init so it causes a flicker at that point
  2. Transitions start a frame late sometimes due to the async/await code, they don't get added to the scene at the right time.
  3. On the initial transition gets setup as a deferred transition and there is also a timing issue when the game starts
  4. I think there might be a few more quirks related to the update/draw as well that I haven't yet figured out

All of these seem fixable with some light refactoring, really things that need to happen simultaneously should not be separate await's but a single atomic call because we are at the mercy of browser scheduling (my theory).

github-actions[bot] commented 5 months ago

This issue hasn't had any recent activity lately and is being marked as stale automatically.