 d59c859a35
			
		
	
	
		d59c859a35
		
			
		
	
	
	
	
		
			
			# Objective - animating a sprite in response to an event is a [common beginner problem](https://www.reddit.com/r/bevy/comments/13xx4v7/sprite_animation_in_bevy/) ## Solution - provide a simple example to show how to animate a sprite in response to an event --------- Co-authored-by: François Mockers <francois.mockers@vleue.com>
		
			
				
	
	
		
			70 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| #![allow(deprecated)]
 | |
| 
 | |
| use crate::{Sprite, TextureAtlas};
 | |
| use bevy_asset::Handle;
 | |
| use bevy_ecs::bundle::Bundle;
 | |
| use bevy_render::{
 | |
|     texture::Image,
 | |
|     view::{InheritedVisibility, ViewVisibility, Visibility},
 | |
| };
 | |
| use bevy_transform::components::{GlobalTransform, Transform};
 | |
| 
 | |
| /// A [`Bundle`] of components for drawing a single sprite from an image.
 | |
| ///
 | |
| /// # Extra behaviours
 | |
| ///
 | |
| /// You may add one or both of the following components to enable additional behaviours:
 | |
| /// - [`ImageScaleMode`](crate::ImageScaleMode) to enable either slicing or tiling of the texture
 | |
| /// - [`TextureAtlas`] to draw a specific section of the texture
 | |
| #[derive(Bundle, Clone, Debug, Default)]
 | |
| 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,
 | |
| }
 | |
| 
 | |
| /// A [`Bundle`] of components for drawing a single sprite from a sprite sheet (also referred
 | |
| /// to as a `TextureAtlas`) or for animated sprites.
 | |
| ///
 | |
| /// Note:
 | |
| /// This bundle is identical to [`SpriteBundle`] with an additional [`TextureAtlas`] component.
 | |
| ///
 | |
| /// Check the following examples for usage:
 | |
| /// - [`animated sprite sheet example`](https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_sheet.rs)
 | |
| /// - [`sprite animation event example`](https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_animation.rs)
 | |
| /// - [`texture atlas example`](https://github.com/bevyengine/bevy/blob/latest/examples/2d/texture_atlas.rs)
 | |
| #[deprecated(
 | |
|     since = "0.14.0",
 | |
|     note = "Use `TextureAtlas` alongside a `SpriteBundle` instead"
 | |
| )]
 | |
| #[derive(Bundle, Clone, Debug, Default)]
 | |
| pub struct SpriteSheetBundle {
 | |
|     /// 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,
 | |
|     /// The sprite sheet base texture
 | |
|     pub texture: Handle<Image>,
 | |
|     /// The sprite sheet texture atlas, allowing to draw a custom section of `texture`.
 | |
|     pub atlas: TextureAtlas,
 | |
|     /// 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,
 | |
| }
 |