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

Add example for pixel-perfect grid snapping in 2D #8112

Merged
merged 15 commits into from
Dec 26, 2023

Conversation

nxsaken
Copy link
Contributor

@nxsaken nxsaken commented Mar 17, 2023

Objective

Provide an example of how to achieve pixel-perfect "grid snapping" in 2D via rendering to a texture. This is a common use case in retro pixel art game development.

Solution

Render sprites to a canvas via a Camera, then use another (scaled up) Camera to render the resulting canvas to the screen. This example is based on the 3d/render_to_texture.rs example. Furthermore, this example demonstrates mixing retro-style graphics with high-resolution graphics, as well as pixel-snapped rendering of a MaterialMesh2dBundle.

@github-actions
Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@nxsaken nxsaken force-pushed the example-render_to_texture_2d branch from d127d27 to 26bf8f3 Compare March 17, 2023 01:16
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Examples An addition or correction to our examples labels Mar 17, 2023
Cargo.toml Outdated Show resolved Hide resolved
@alice-i-cecile
Copy link
Member

Very nice stuff. I only have a few nits.

@nxsaken nxsaken force-pushed the example-render_to_texture_2d branch from 26bf8f3 to dcafb04 Compare March 17, 2023 01:20
@nxsaken nxsaken force-pushed the example-render_to_texture_2d branch from dcafb04 to b21f76a Compare March 17, 2023 01:27
@alice-i-cecile
Copy link
Member

Solid work. In the future, adding more commits rather than rebasing will make it slightly easier for reviewers to tell what's changed :)

@nxsaken
Copy link
Contributor Author

nxsaken commented Mar 17, 2023

Got it, thank you for the swift review!

@rparrett
Copy link
Contributor

I'm not asking for this change right now, but what do we think about combining this example pixel_perfect.rs?

That example seems to exist solely to have a place to put bevy_pixel_light.png and doesn't actually seem to attempt to do anything "pixel perfect."

@nxsaken
Copy link
Contributor Author

nxsaken commented Mar 17, 2023

It does seem like this example covers the other one. I also realized that the sprite in pixel_perfect.rs is not even really pixel art, the artwork is high-res. I can take a look later and see if it makes sense to combine them or remove the old example

examples/2d/pixel_grid_snap.rs Show resolved Hide resolved
examples/2d/pixel_grid_snap.rs Outdated Show resolved Hide resolved
examples/2d/pixel_grid_snap.rs Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Dec 26, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 26, 2023
Merged via the queue into bevyengine:main with commit 8067e46 Dec 26, 2023
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants