Struct bevy::sprite::TextureAtlas
pub struct TextureAtlas {
pub texture: Handle<Image>,
pub size: Vec2,
pub textures: Vec<Rect, Global>,
/* private fields */
}
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
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. The 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 len(&self) -> usize
pub fn len(&self) -> usize
The number of textures in the TextureAtlas
pub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if there are no textures in the TextureAtlas
pub fn get_texture_index(
&self,
texture: impl Into<AssetId<Image>>
) -> Option<usize>
pub fn get_texture_index( &self, texture: impl Into<AssetId<Image>> ) -> Option<usize>
Returns the index of the texture corresponding to the given image handle in the TextureAtlas
Trait Implementations§
§impl Clone for TextureAtlas
impl Clone for TextureAtlas
§fn clone(&self) -> TextureAtlas
fn clone(&self) -> TextureAtlas
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for TextureAtlas
impl Debug for TextureAtlas
§impl FromReflect for TextureAtlaswhere
Handle<Image>: FromReflect + TypePath,
Vec2: FromReflect + TypePath,
Vec<Rect, Global>: FromReflect + TypePath,
Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
impl FromReflect for TextureAtlaswhere Handle<Image>: FromReflect + TypePath, Vec2: FromReflect + TypePath, Vec<Rect, Global>: FromReflect + TypePath, Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
§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 TextureAtlaswhere
Handle<Image>: FromReflect + TypePath,
Vec2: FromReflect + TypePath,
Vec<Rect, Global>: FromReflect + TypePath,
Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
impl GetTypeRegistration for TextureAtlaswhere Handle<Image>: FromReflect + TypePath, Vec2: FromReflect + TypePath, Vec<Rect, Global>: FromReflect + TypePath, Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
§impl Reflect for TextureAtlaswhere
Handle<Image>: FromReflect + TypePath,
Vec2: FromReflect + TypePath,
Vec<Rect, Global>: FromReflect + TypePath,
Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
impl Reflect for TextureAtlaswhere Handle<Image>: FromReflect + TypePath, Vec2: FromReflect + TypePath, Vec<Rect, Global>: FromReflect + TypePath, Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
§fn into_any(self: Box<TextureAtlas, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<TextureAtlas, Global>) -> Box<dyn Any, 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, Global>
fn into_reflect(self: Box<TextureAtlas, Global>) -> Box<dyn Reflect, 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, Global>
fn clone_value(&self) -> Box<dyn Reflect, Global>
Reflect
trait object. Read more§fn set(
&mut self,
value: Box<dyn Reflect, Global>
) -> Result<(), Box<dyn Reflect, Global>>
fn set( &mut self, value: Box<dyn Reflect, Global> ) -> Result<(), Box<dyn Reflect, 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 debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
§impl Struct for TextureAtlaswhere
Handle<Image>: FromReflect + TypePath,
Vec2: FromReflect + TypePath,
Vec<Rect, Global>: FromReflect + TypePath,
Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
impl Struct for TextureAtlaswhere Handle<Image>: FromReflect + TypePath, Vec2: FromReflect + TypePath, Vec<Rect, Global>: FromReflect + TypePath, Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
§fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>
name
as a &dyn Reflect
.§fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>
fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>
name
as a
&mut dyn Reflect
.§fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>
index
as a
&dyn Reflect
.§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
.§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
.§impl TypePath for TextureAtlaswhere
Handle<Image>: FromReflect + TypePath,
Vec2: FromReflect + TypePath,
Vec<Rect, Global>: FromReflect + TypePath,
Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
impl TypePath for TextureAtlaswhere Handle<Image>: FromReflect + TypePath, Vec2: FromReflect + TypePath, Vec<Rect, Global>: FromReflect + TypePath, Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
§impl Typed for TextureAtlaswhere
Handle<Image>: FromReflect + TypePath,
Vec2: FromReflect + TypePath,
Vec<Rect, Global>: FromReflect + TypePath,
Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
impl Typed for TextureAtlaswhere Handle<Image>: FromReflect + TypePath, Vec2: FromReflect + TypePath, Vec<Rect, Global>: FromReflect + TypePath, Option<HashMap<AssetId<Image>, usize, BuildHasherDefault<AHasher>, Global>>: FromReflect + TypePath,
§impl VisitAssetDependencies for TextureAtlas
impl VisitAssetDependencies for TextureAtlas
fn visit_dependencies(&self, visit: &mut impl FnMut(UntypedAssetId))
impl Asset 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.§impl<A> AssetContainer for Awhere
A: Asset,
impl<A> AssetContainer for Awhere A: Asset,
fn insert(self: Box<A, Global>, id: UntypedAssetId, world: &mut World)
fn asset_type_name(&self) -> &'static str
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn 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, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, 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
.§fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn 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.§fn 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.§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere T: TypePath,
§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
.§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
.§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
.§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> GetPath for Twhere
T: Reflect + ?Sized,
impl<T> GetPath for Twhere T: Reflect + ?Sized,
§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>
) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p> ) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p> ) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>( &self, path: impl ReflectPath<'p> ) -> Result<&T, ReflectPathError<'p>>where T: Reflect,
path
. Read more§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>( &mut self, path: impl ReflectPath<'p> ) -> Result<&mut T, ReflectPathError<'p>>where T: Reflect,
path
. Read more