mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 22:20:20 +00:00
7d40e3ec87
# Objective Continue migration of bevy APIs to required components, following guidance of https://hackmd.io/@bevy/required_components/ ## Solution - Make `Sprite` require `Transform` and `Visibility` and `SyncToRenderWorld` - move image and texture atlas handles into `Sprite` - deprecate `SpriteBundle` - remove engine uses of `SpriteBundle` ## Testing ran cargo tests on bevy_sprite and tested several sprite examples. --- ## Migration Guide Replace all uses of `SpriteBundle` with `Sprite`. There are several new convenience constructors: `Sprite::from_image`, `Sprite::from_atlas_image`, `Sprite::from_color`. WARNING: use of `Handle<Image>` and `TextureAtlas` as components on sprite entities will NO LONGER WORK. Use the fields on `Sprite` instead. I would have removed the `Component` impls from `TextureAtlas` and `Handle<Image>` except it is still used within ui. We should fix this moving forward with the migration.
36 lines
1,012 B
Rust
36 lines
1,012 B
Rust
//! Demonstrates how to use transparency in 2D.
|
|
//! Shows 3 bevy logos on top of each other, each with a different amount of transparency.
|
|
|
|
use bevy::prelude::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_systems(Startup, setup)
|
|
.run();
|
|
}
|
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
commands.spawn(Camera2d);
|
|
|
|
let sprite_handle = asset_server.load("branding/icon.png");
|
|
|
|
commands.spawn(Sprite::from_image(sprite_handle.clone()));
|
|
commands.spawn((
|
|
Sprite {
|
|
image: sprite_handle.clone(),
|
|
// Alpha channel of the color controls transparency.
|
|
color: Color::srgba(0.0, 0.0, 1.0, 0.7),
|
|
..default()
|
|
},
|
|
Transform::from_xyz(100.0, 0.0, 0.0),
|
|
));
|
|
commands.spawn((
|
|
Sprite {
|
|
image: sprite_handle,
|
|
color: Color::srgba(0.0, 1.0, 0.0, 0.3),
|
|
..default()
|
|
},
|
|
Transform::from_xyz(200.0, 0.0, 0.0),
|
|
));
|
|
}
|