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

Sprite visibility #80

Merged
merged 3 commits into from
Jan 12, 2024
Merged

Sprite visibility #80

merged 3 commits into from
Jan 12, 2024

Conversation

tehsmeely
Copy link
Contributor

This PR exposes the setVisible and isVisible sprite methods in the C api as Sprite::set_visible and Sprite::is_visible respectively
It also extends the hello_world example to have a sprite that toggles visibility on pressing A.

On adding the example i was sent down a rabbit-hole of some confusing behaviour with Graphics functions when sprites are added.
Notably as soon as one calls SpriteManager::new_sprite all the graphics functions and draw_fps stop working.
The first solution is that the graphics Context stack seems to get messed up with sprite drawing so if we want to draw to display framebuffer we must clear context. Bindings existed for this already (as part of the Graphics::with_context) so i just exposed a clear_context to be called before attempting to write to display framebuffer.

Curiously, though, this also changes a lot of the sprite drawing semantics and we have to start behaving properly with marking sprites as dirty for them to draw. in the Hello_world example this meant implementing the update_sprite function in its impl Game and always marking all sprites as dirty every frame.
In my personal project this required one tweak to a sprite using custom draw, but has otherwise drastically reduced per-frame redraws so seems like a big win!

@boozook boozook merged commit df48ecd into pd-rs:main Jan 12, 2024
1 check passed
@tehsmeely tehsmeely deleted the sprite-visibility branch January 21, 2024 15:34
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

2 participants