mirror of
https://github.com/bevyengine/bevy
synced 2024-12-22 11:03:06 +00:00
a636145d90
# Objective - Fix #3188 - Allow creating a `PipelinedSpriteBundle` without an image, just a plain color ```rust PipelinedSpriteBundle { sprite: Sprite { color: Color::rgba(0.8, 0.0, 0.0, 0.3), custom_size: Some(Vec2::new(500.0, 500.0)), ..Default::default() }, ..Default::default() } ``` ## Solution - The default impl for `Image` was creating a one pixel image with all values at `1`. I changed it to `255` as picking `1` for it doesn't really make sense, it should be either `0` or `255` - I created a static handle and added the default image to the assets with this handle - I changed the default impl for `PipelinedSpriteBundle` to use this handle
52 lines
1.9 KiB
Rust
52 lines
1.9 KiB
Rust
use crate::{
|
|
texture_atlas::{TextureAtlas, TextureAtlasSprite},
|
|
Sprite,
|
|
};
|
|
use bevy_asset::Handle;
|
|
use bevy_ecs::bundle::Bundle;
|
|
use bevy_render2::{
|
|
texture::{Image, DEFAULT_IMAGE_HANDLE},
|
|
view::{ComputedVisibility, Visibility},
|
|
};
|
|
use bevy_transform::components::{GlobalTransform, Transform};
|
|
|
|
#[derive(Bundle, Clone)]
|
|
pub struct PipelinedSpriteBundle {
|
|
pub sprite: Sprite,
|
|
pub transform: Transform,
|
|
pub global_transform: GlobalTransform,
|
|
pub texture: Handle<Image>,
|
|
/// User indication of whether an entity is visible
|
|
pub visibility: Visibility,
|
|
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
|
|
pub computed_visibility: ComputedVisibility,
|
|
}
|
|
|
|
impl Default for PipelinedSpriteBundle {
|
|
fn default() -> Self {
|
|
Self {
|
|
sprite: Default::default(),
|
|
transform: Default::default(),
|
|
global_transform: Default::default(),
|
|
texture: DEFAULT_IMAGE_HANDLE.typed(),
|
|
visibility: Default::default(),
|
|
computed_visibility: Default::default(),
|
|
}
|
|
}
|
|
}
|
|
/// A Bundle of components for drawing a single sprite from a sprite sheet (also referred
|
|
/// to as a `TextureAtlas`)
|
|
#[derive(Bundle, Clone, Default)]
|
|
pub struct PipelinedSpriteSheetBundle {
|
|
/// The specific sprite from the texture atlas to be drawn
|
|
pub sprite: TextureAtlasSprite,
|
|
/// A handle to the texture atlas that holds the sprite images
|
|
pub texture_atlas: Handle<TextureAtlas>,
|
|
/// Data pertaining to how the sprite is drawn on the screen
|
|
pub transform: Transform,
|
|
pub global_transform: GlobalTransform,
|
|
/// User indication of whether an entity is visible
|
|
pub visibility: Visibility,
|
|
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
|
|
pub computed_visibility: ComputedVisibility,
|
|
}
|