Fix drawing order of sprites and other graphics #52
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 theSpriteManager
will 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_lives
repo before and after this change.Before:
![1](https://private-user-images.githubusercontent.com/6700637/263404310-d69f11cd-24b2-4c07-aaef-4ca925672ccf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk5MjQxODMsIm5iZiI6MTczOTkyMzg4MywicGF0aCI6Ii82NzAwNjM3LzI2MzQwNDMxMC1kNjlmMTFjZC0yNGIyLTRjMDctYWFlZi00Y2E5MjU2NzJjY2YucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTlUMDAxMTIzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Y2RlOTJhN2Q5NmRhMzk4M2M5ODhjMWEyYzE2YjdiZGE1ZGFkZDg5OTgwZTYxN2YyYTY1NzQ4OGQyOWM0MjFkMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.a37FpX965NjwiHmTSP6MXo4oBv5WAMv9UDJZSOgSqE4)
After:
![2](https://private-user-images.githubusercontent.com/6700637/263404312-99ec4527-f18a-4d2f-b819-5fe13719b126.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk5MjQxODMsIm5iZiI6MTczOTkyMzg4MywicGF0aCI6Ii82NzAwNjM3LzI2MzQwNDMxMi05OWVjNDUyNy1mMThhLTRkMmYtYjgxOS01ZmUxMzcxOWIxMjYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTlUMDAxMTIzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Njk3MTA3ZWYxM2ZhNzY0YzI1NDRlNDllOGIxNjg0NjhmZWRhNjEwZDNmNjI1Yzk4MTc2YTJmNTcxYTNkNzg0YiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.kHUoZ-6qTpsrI6Zj8HBLdxAOklmOJiH0xwoPpVoaSMY)
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
.