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

Fix drawing order of sprites and other graphics #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ruin0x11
Copy link
Contributor

I'm not sure why but playdate->sprite->updateAndDrawSprites(void) in the C API seems to clear the screen before drawing anything. So a game that allocates any sprites through the SpriteManager will be unable to draw things in the Game::update() method anymore because that method is called before sprite updates within crankshaft (even if the sprites are never added to the manager).

To fix this, I swapped the order of update_and_draw_sprites() and Game::update() in crankshaft's update method. I tested the linked nine_lives repo before and after this change.

Before:
1

After:
2

I also had to remove the call to Graphics.clear() in the update method for it to work correctly.

As for how to draw behind sprites given this change, from what I understand the Lua API provides a method that allocates a "background sprite" and allows you to specify how it should be rendered. But there isn't an equivalent function in the C API, and there's nothing mentioning this screen clearing behavior in either the Lua or C API documentation. I'm assuming that drawing things behind sprites with the core graphics API is unsupported for some reason, and this method would have to be reimplemented in crankshaft.

@boozook
Copy link
Member

boozook commented Sep 3, 2023

Awesome find, thanks! Is it breaking change for other users? 🤔

@lyonbeckers
Copy link
Contributor

I think my only reservation would be that any game logic that should update a sprite won't be applied until the next frame. So if input is handled in Game::update, the sprite wouldn't move until the next frame. That might feel noticeably unresponsive at 20 fps, but I haven't tried it yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants