Fix drawing order of sprites and other graphics#52
Open
Ruin0x11 wants to merge 1 commit intopd-rs:mainfrom
Open
Fix drawing order of sprites and other graphics#52Ruin0x11 wants to merge 1 commit intopd-rs:mainfrom
Ruin0x11 wants to merge 1 commit intopd-rs:mainfrom
Conversation
Member
|
Awesome find, thanks! Is it breaking change for other users? 🤔 |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 theSpriteManagerwill be unable to draw things in theGame::update()method anymore because that method is called before sprite updates withincrankshaft(even if the sprites are never added to the manager).To fix this, I swapped the order of
update_and_draw_sprites()andGame::update()incrankshaft's update method. I tested the linkednine_livesrepo before and after this change.Before:

After:

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.