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

Merge SpriteBundle and TextureAtlasBundle #7123

Closed
cBournhonesque opened this issue Jan 7, 2023 · 3 comments
Closed

Merge SpriteBundle and TextureAtlasBundle #7123

cBournhonesque opened this issue Jan 7, 2023 · 3 comments
Labels
A-Rendering Drawing game state to the screen C-Enhancement A new feature C-Usability A simple quality-of-life change that makes Bevy easier to use

Comments

@cBournhonesque
Copy link
Contributor

cBournhonesque commented Jan 7, 2023

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

My game is composed of entities that contain a SpriteBundle bundle or a SpriteSheetBundle bundle.
When I want to update the color of an entity, I need to check every time if it contains a Sprite bundle or a TextureAtlasSprite bundle to be able to set the inner color field of these components. I don't want to have to make this check, because functionally it doesn't matter to me if an entity is rendered via a Sprite or a SpriteSheet, I just want to change the color of the texture.

Basically I believe the Sprite and TextureAtlasSprite components contain data that is too coupled.

Ideally I would like to be able to set Color only once for the entity, and then have the color be propagated to any sprite bundle of the entity. Same for 'anchor' or other sprite-related fields like flip_x, etc.

What solution would you like?

I think i would like to see most fields common to 'Sprite' and 'TextureAtlasSprite' grouped into a separate component.
Something like:

pub struct SpriteRenderComponent {
    pub color: Color,
    pub flip_x: bool,
    pub flip_y: bool,
    pub custom_size: Option<Vec2>,
    pub rect: Option<Rect>,
    pub anchor Anchor,
}

And then change the bundles into:

pub struct SpriteBundle{
   pub render: SpriteRenderComponent,
   pub texture: SpriteTextureEnum,
   ...
}

#[derive(Component)]
pub enum SpriteTextureComponent{
   SpriteTexture(Handle<Image>),
   TextureAtlasSpriteTexture{texture_atlas: Handle<TextureAtlas>, index: usize},
}

and then all sprite-based entities can just use the SpriteBundle, instead of having separate SpriteBundle or TextureAtlasBundle.
This way I can change the color of all sprite-based entities without having to worry if they were created using a texture-atlas or not (which is just an inner implementation detail)

The solution you propose for the problem presented.

What alternative(s) have you considered?

  • I was thinking of having a global 'Color' component per entity, which can be propagated to sprite.color or textureAtlasSprite.color, but that seems overly complicated (some entities do not need a color) + the actual problem is that the Sprite and TextureAtlasSprite components are doing too much, some information should be shared between them.
@cBournhonesque cBournhonesque added C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled labels Jan 7, 2023
@rparrett
Copy link
Contributor

rparrett commented Jan 8, 2023

Linking this related PR which I think would address the issue #5103

@rparrett rparrett added A-Rendering Drawing game state to the screen C-Usability A simple quality-of-life change that makes Bevy easier to use and removed S-Needs-Triage This issue needs to be labelled labels Jan 8, 2023
@cBournhonesque
Copy link
Contributor Author

Ah I didn't see the PR; that's exactly what I wanted, perfect :D

@mgi388
Copy link
Contributor

mgi388 commented Mar 28, 2024

@cBournhonesque I think you should be able to close this since #5103 was merged?

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-Enhancement A new feature C-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

No branches or pull requests

3 participants