Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset causes flash of incorrect position in tutorial #2536

Open
cdeil opened this issue Jan 31, 2025 · 2 comments
Open

Reset causes flash of incorrect position in tutorial #2536

cdeil opened this issue Jan 31, 2025 · 2 comments
Labels
examples issues related to examples

Comments

@cdeil
Copy link
Contributor

cdeil commented Jan 31, 2025

I was going through the platformer tutorial. It's really nice, thank you!

One small issue I noticed is that when using ESC to reset it works, but there's a fraction of a second where the player is in the lower left before it jumps to the center. This is with Python 3.13 on MacOS.

Is there a way to restructure the code to avoid this "flash of mispositioned content"?

To reproduce run this:

python -m arcade.examples.platform_tutorial.06_reset

Here's a screen screenshot showing the incorrect positioning:

Image

Here's a recording:

Screen.Recording.2025-01-31.at.19.56.56.mov
@einarf
Copy link
Member

einarf commented Feb 1, 2025

Just calling setup() from the key input callback function is a bit brutal because all state changes should ideally always be done in on_update.

If we instead set a reset flag

        if key == arcade.key.ESCAPE:
            self.reset = True

.. and pick up the reset state in on_update

    def on_update(self, delta_time):
        if self.reset:
            self.setup()
            self.reset = False

What happens here is that you get the default camera position at 0, 0 because you re-create it completely so you get one frame with default camera.. then next frame with centered camera. The is usually on_update, on_draw, process input BUT this is never guaranteed. on_draw can happen more than once per cycle depending on os, environment and all window update settings.

An even better solution is to create a smarter and more light weight reset function but that would probably look very different based on what game you are creating?

@einarf
Copy link
Member

einarf commented Feb 2, 2025

This might also be somewhat related to pyglet/pyglet#1268 since events can be skipped BUT you can also configure a custom draw an update rate so the fact still stands that on_update is always where scene changes should be done.

@einarf einarf added the examples issues related to examples label Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples issues related to examples
Projects
None yet
Development

No branches or pull requests

2 participants