Sprite Origin, and Pixel Perfect Sprites #3149
Replies: 3 comments
-
Does anybody have an answer to this? 2D is pretty difficult because of this issue. |
Beta Was this translation helpful? Give feedback.
-
You could try making the sprite a child of an entity with It'd be important that the parent's location is used instead of the sprite's in gameplay code, because transform propagation happens late in the frame, so you'll use the previous frame's position otherwise. For pixel perfectness: I haven't tried this myself, but tried throwing away the fraction of the sprite's position with something like "floor"? |
Beta Was this translation helpful? Give feedback.
-
I realize this is very old, but I found a solution to changing the origin that works for me. By using this code I offset the camera to make the origin seem like the top left: fn setup(mut commands: Commands, win: Res<Windows>) {
let w = win.get_primary().unwrap();
// set origin to top left
let mut camera = OrthographicCameraBundle::new_2d();
camera.transform.translation.x += w.width() / 2.;
camera.transform.translation.y += w.height() / 2.;
commands.spawn_bundle(camera);
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to set the origin for a sprite to the corner, rather than the centre? The default method means that sprites with an odd number of horizontal pixels are misaligned with sprites with an even number of horizontal pixels.
Also, is there a way to ensure that sprites are always natively pixel perfect?
Beta Was this translation helpful? Give feedback.
All reactions