1
- use crate :: { Rect , TextureAtlas } ;
2
- use bevy_asset:: { Assets , Handle } ;
3
1
use bevy_ecs:: component:: Component ;
4
2
use bevy_math:: Vec2 ;
5
3
use bevy_reflect:: Reflect ;
@@ -21,41 +19,6 @@ pub struct Sprite {
21
19
pub anchor : Anchor ,
22
20
}
23
21
24
- /// Component for sprite sheets containing a handle to [`TextureAtlas`] and the index of the current
25
- /// section of the sheet.
26
- ///
27
- /// A texture atlas contains various *sections* or *cuts* of a given texture, allowing users to have a single
28
- /// image file for sprite animation or various elements.
29
- /// You can change the [`index`](Self::index) of the sheet to animate the sprite or to pick a *section* of the texture.
30
- ///
31
- /// Check the following examples for usage:
32
- /// - [`animated sprite sheet example`](https://github.com/bevyengine/bevy/blob/main/examples/2d/sprite_sheet.rs)
33
- /// - [`texture atlas example`](https://github.com/bevyengine/bevy/blob/main/examples/2d/texture_atlas.rs)
34
- #[ derive( Component , Default , Debug , Clone , Reflect ) ]
35
- pub struct SpriteSheet {
36
- /// Texture atlas handle
37
- pub texture_atlas : Handle < TextureAtlas > ,
38
- /// Texture atlas section index
39
- pub index : usize ,
40
- }
41
-
42
- impl From < Handle < TextureAtlas > > for SpriteSheet {
43
- fn from ( texture_atlas : Handle < TextureAtlas > ) -> Self {
44
- Self {
45
- texture_atlas,
46
- index : 0 ,
47
- }
48
- }
49
- }
50
-
51
- impl SpriteSheet {
52
- /// Retrieves the current texture [`Rect`] of the sprite sheet according to the section `index`
53
- pub fn texture_rect ( & self , texture_atlases : & Assets < TextureAtlas > ) -> Option < Rect > {
54
- let atlas = texture_atlases. get ( & self . texture_atlas ) ?;
55
- atlas. textures . get ( self . index ) . copied ( )
56
- }
57
- }
58
-
59
22
/// How a sprite is positioned relative to its [`Transform`](bevy_transform::components::Transform).
60
23
/// It defaults to `Anchor::Center`.
61
24
#[ derive( Debug , Clone , Reflect ) ]
0 commit comments