---
# System prepended metadata

title: Sprites
tags: [Required-Components]

---

# Bundles

## `SpriteBundle`

```rust
pub struct SpriteBundle {
    /// Specifies the rendering properties of the sprite, such as color tint and flip.
    pub sprite: Sprite,
    /// The local transform of the sprite, relative to its parent.
    pub transform: Transform,
    /// The absolute transform of the sprite. This should generally not be written to directly.
    pub global_transform: GlobalTransform,
    /// A reference-counted handle to the image asset to be drawn.
    pub texture: Handle<Image>,
    /// User indication of whether an entity is visible
    pub visibility: Visibility,
    /// Inherited visibility of an entity.
    pub inherited_visibility: InheritedVisibility,
    /// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
    pub view_visibility: ViewVisibility,
}

// Intended to be used in combination with a TextureAtlas component to use a "sprite sheet"
#[derive(Component)]
pub struct TextureAtlas {
    /// Texture atlas layout handle
    pub layout: Handle<TextureAtlasLayout>,
    /// Texture atlas section index
    pub index: usize,
}

// We should think about if / how TextureAtlas and Handle<Image> will relate to each other in the event
// that we use a wrapper component for Handle<Image>. Should we merge Handle<Image> into Sprite?
```

### Proposal 1 (Selected)

```rust
#[derive(Component)]
#[require(Transform, Visibility)]
pub struct Sprite {
    /// Handle of the sprite to render, or the atlas image if `atlas` is some.
    image: Handle<Image>,
    /// Optional texture atlas information
    atlas: Option<TextureAtlas>,
    ...
}

pub struct TextureAtlas {
    /// Texture atlas layout handle
    pub layout: Handle<TextureAtlasLayout>,
    /// Texture atlas section index
    pub index: usize,
}
```

Simplest to just smush them together?

### Proposal 2

```rust
#[derive(Component)]
#[require(Sprite)]
pub struct ImageSprite {
    pub image: Handle<Image>,
}
    
#[derive(Component)]
#[require(Sprite)]
pub struct AtlasSprite {
    pub image: Handle<Image>,
    pub layout: Handle<TextureAtlasLayout>,
    pub index: usize,
}

#[derive(Component)]
#[require(Transform, Visibility)]
pub struct Sprite;
```

We could also pull the common sprite data out into it's own component.

### Proposal 3

```rust
#[derive(Component)]
#[require(Transform, Visibility)]
pub struct Sprite {
    /// Handle of the sprite to render, or the atlas image if `atlas` is some.
    image: Handle<Image>,
    // other sprite fields here
}

#[derive(Component)]
#[require(Sprite)]
pub struct AtlasSprite {
    /// Texture atlas layout handle
    pub layout: Handle<TextureAtlasLayout>,
    /// Texture atlas section index
    pub index: usize,
}
```