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 pivot (offset) #1616

Closed
DarkMara opened this issue Mar 11, 2021 · 5 comments
Closed

Sprite pivot (offset) #1616

DarkMara opened this issue Mar 11, 2021 · 5 comments
Labels
A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@DarkMara
Copy link

What problem does this solve or what need does it fill?

It allows each sprite to be drawn at a different offset on the texture. For example, on a character sprite sheet, the pivot is often put at the character's feet, so that they always appear in the same place even if the sprites are different sizes or the pixels do not line up exactly.

What solution would you like?

There should be a Vec2 on both Sprite and TextureAtlasSprite that determines the offset the sprite should be drawn at. It could be called pivot or offset.

What alternative(s) have you considered?

The alternative is to offset the transform every time you change the sprite. It's tedious.

Additional context

Unity includes an enum that lets you to automatically put the pivot at certain parts of the sprite, like TopLeft or Center. I'm not sure if that should be on the sprite or should just be handled in the editor.

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy labels Mar 11, 2021
@mockersf
Copy link
Member

This could be solved by using a hierarchy of entity:

  • children would specify translation so that the sprite is displayed in the offset you want of its parent
  • parent would specify rotation

Would that work for you?

@DarkMara
Copy link
Author

That doesn't solve the issue. Each sprite could have a different pivot, so as I said, you'd have to change the child's transform every time the sprite changes. That's what I'm doing currently as a workaround, but it's not a good solution. This feature is present in both Godot and Unity, and it should be in Bevy also.

@DarkMara
Copy link
Author

DarkMara commented Mar 14, 2021

I attempted to implement this myself, but I didn't know how to apply the offset to the SpriteTransform matrix in the shader. The offset is in pixels, so I guess it would need to be converted to world coordinates and then added to the translation.

@ManevilleF
Copy link
Contributor

+1

Since we can generate sprites programatically it would be nice to specify a pivot.
Using hierarchy as an anchor works but it adds complexity both in code and the runtime, moving/rotating a single sprite with a custom pivot would be faster than moving/rotating a parent object

@drakmaniso
Copy link

An easily configurable offset would also be really useful for pixel-art sprites. With the current centered behavior, odd-sized textures requires an offset of 0.5 to be aligned on screen pixels.

@bors bors bot closed this as completed in 8e864fd Apr 4, 2022
aevyrie pushed a commit to aevyrie/bevy that referenced this issue Jun 7, 2022
# Objective

- Fixes bevyengine#1616, fixes bevyengine#2225
- Let user specify an anchor for a sprite

## Solution

- Add an enum for an anchor point for most common values, with a variant for a custom point
- Defaults to Center to not change current behaviour


Co-authored-by: François <[email protected]>
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

- Fixes bevyengine#1616, fixes bevyengine#2225
- Let user specify an anchor for a sprite

## Solution

- Add an enum for an anchor point for most common values, with a variant for a custom point
- Defaults to Center to not change current behaviour


Co-authored-by: François <[email protected]>
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-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants