Struct bevy::sprite::TextureAtlas
pub struct TextureAtlas {
pub texture: Handle<Image>,
pub size: Vec2,
pub textures: Vec<Rect, Global>,
pub texture_handles: Option<HashMap<Handle<Image>, usize, RandomState, Global>>,
}
Expand description
An atlas containing multiple textures (like a spritesheet or a tilemap). Example usage animating sprite. Example usage loading sprite sheet.
Fields
texture: Handle<Image>
The handle to the texture in which the sprites are stored
size: Vec2
textures: Vec<Rect, Global>
The specific areas of the atlas where each texture can be found
texture_handles: Option<HashMap<Handle<Image>, usize, RandomState, Global>>
Implementations
impl TextureAtlas
impl TextureAtlas
pub fn new_empty(texture: Handle<Image>, dimensions: Vec2) -> TextureAtlas
pub fn new_empty(texture: Handle<Image>, dimensions: Vec2) -> TextureAtlas
Create a new TextureAtlas
that has a texture, but does not have
any individual sprites specified
pub fn from_grid(
texture: Handle<Image>,
tile_size: Vec2,
columns: usize,
rows: usize,
padding: Option<Vec2>,
offset: Option<Vec2>
) -> TextureAtlas
pub fn from_grid(
texture: Handle<Image>,
tile_size: Vec2,
columns: usize,
rows: usize,
padding: Option<Vec2>,
offset: Option<Vec2>
) -> TextureAtlas
Generate a TextureAtlas
by splitting a texture into a grid where each
tile_size
by tile_size
grid-cell is one of the textures in the
atlas. Grid cells are separated by some padding
, and the grid starts
at offset
pixels from the top left corner. Resulting TextureAtlas
is
indexed left to right, top to bottom.
pub fn add_texture(&mut self, rect: Rect) -> usize
pub fn add_texture(&mut self, rect: Rect) -> usize
Add a sprite to the list of textures in the TextureAtlas
returns an index to the texture which can be used with TextureAtlasSprite
Arguments
rect
- The section of the atlas that contains the texture to be added, from the top-left corner of the texture to the bottom-right corner
pub fn is_empty(&self) -> bool
pub fn get_texture_index(&self, texture: &Handle<Image>) -> Option<usize>
Trait Implementations
impl Clone for TextureAtlas
impl Clone for TextureAtlas
fn clone(&self) -> TextureAtlas
fn clone(&self) -> TextureAtlas
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreimpl Debug for TextureAtlas
impl Debug for TextureAtlas
impl FromReflect for TextureAtlaswhere
Handle<Image>: FromReflect,
Vec2: FromReflect,
Vec<Rect, Global>: FromReflect,
Option<HashMap<Handle<Image>, usize, RandomState, Global>>: FromReflect,
impl FromReflect for TextureAtlaswhere
Handle<Image>: FromReflect,
Vec2: FromReflect,
Vec<Rect, Global>: FromReflect,
Option<HashMap<Handle<Image>, usize, RandomState, Global>>: FromReflect,
fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<TextureAtlas>
fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<TextureAtlas>
Self
from a reflected value.impl GetTypeRegistration for TextureAtlas
impl GetTypeRegistration for TextureAtlas
impl Reflect for TextureAtlas
impl Reflect for TextureAtlas
fn get_type_info(&self) -> &'static TypeInfo
fn get_type_info(&self) -> &'static TypeInfo
fn into_any(self: Box<TextureAtlas, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<TextureAtlas, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Any>
.fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any
.fn into_reflect(
self: Box<TextureAtlas, Global>
) -> Box<dyn Reflect + 'static, Global>
fn into_reflect(
self: Box<TextureAtlas, Global>
) -> Box<dyn Reflect + 'static, Global>
fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn clone_value(&self) -> Box<dyn Reflect + 'static, Global>
fn clone_value(&self) -> Box<dyn Reflect + 'static, Global>
Reflect
trait object. Read morefn set(
&mut self,
value: Box<dyn Reflect + 'static, Global>
) -> Result<(), Box<dyn Reflect + 'static, Global>>
fn set(
&mut self,
value: Box<dyn Reflect + 'static, Global>
) -> Result<(), Box<dyn Reflect + 'static, Global>>
fn apply(&mut self, value: &(dyn Reflect + 'static))
fn apply(&mut self, value: &(dyn Reflect + 'static))
fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_owned(self: Box<TextureAtlas, Global>) -> ReflectOwned
fn reflect_owned(self: Box<TextureAtlas, Global>) -> ReflectOwned
fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
impl Struct for TextureAtlas
impl Struct for TextureAtlas
fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
index
as a &mut dyn Reflect
. Read morefn iter_fields(&self) -> FieldIter<'_>ⓘ
fn iter_fields(&self) -> FieldIter<'_>ⓘ
fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
.impl TypeUuid for TextureAtlas
impl TypeUuid for TextureAtlas
Auto Trait Implementations
impl RefUnwindSafe for TextureAtlas
impl Send for TextureAtlas
impl Sync for TextureAtlas
impl Unpin for TextureAtlas
impl UnwindSafe for TextureAtlas
Blanket Implementations
impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist. Read moresourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read morefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read morefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read morefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read moreimpl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
impl<T> GetPath for Twhere
T: Reflect,
impl<T> GetPath for Twhere
T: Reflect,
fn path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
fn path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read morefn path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read morefn get_path<T, 'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r T, ReflectPathError<'p>>where
T: Reflect,
fn get_path<T, 'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r T, ReflectPathError<'p>>where
T: Reflect,
path
.fn get_path_mut<T, 'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>>where
T: Reflect,
fn get_path_mut<T, 'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read more