pub struct Clips { /* private fields */ }Expand description
The clips, by handle, and by name for those that have one: a resource
that the engine adds. An Animator names its clip by the handle that
Clips::add, Clips::add_named or Clips::add_atlas gives.
It is the only place Handle<Clip>s come from: a clip is not an asset
of the AssetServer (ADR-0024).
Implementations§
Source§impl Clips
impl Clips
Sourcepub fn add(&mut self, clip: Clip) -> Handle<Clip>
pub fn add(&mut self, clip: Clip) -> Handle<Clip>
Adds clip, with no name, and returns its handle.
Sourcepub fn add_named(
&mut self,
name: impl Into<String>,
clip: Clip,
) -> Result<Handle<Clip>, ClipError>
pub fn add_named( &mut self, name: impl Into<String>, clip: Clip, ) -> Result<Handle<Clip>, ClipError>
Adds clip named name, and returns its handle.
§Errors
ClipError::NameTaken if a clip has that name: none is added.
Sourcepub fn add_atlas(
&mut self,
atlas: &Atlas,
pages: &[Handle<Texture>],
) -> Result<Vec<Handle<Clip>>, ClipError>
pub fn add_atlas( &mut self, atlas: &Atlas, pages: &[Handle<Texture>], ) -> Result<Vec<Handle<Clip>>, ClipError>
Adds every clip of every sprite of atlas, each named by its sprite
and its own name, as sprites/person/walk, with its frames placed
by ClipFrame::from_atlas in pages, the textures of the atlas’s
pages (Atlas::load_pages). Returns their handles sprite by sprite,
in the atlas’s order, and each sprite’s clips by name. A looping clip
is Playback::Loop; the others Playback::Once.
An atlas is known by its pages. One added before with the same
pages, whose clips are not all removed, is not added again: the
result is the handles it gave, and the atlas is held once more, as
Clips::release_atlas lets go. So a level and the game can each
add an atlas they share, in either order, and the clips stay until
the last lets go of it (ADR-0038).
§Errors
ClipError::WrongPages if pages is not one texture a page, and
ClipError::NameTaken if a clip has one of their names, as when
two atlases have a sprite of one name. Then none is added.
Sourcepub fn release_atlas(&mut self, pages: &[Handle<Texture>]) -> bool
pub fn release_atlas(&mut self, pages: &[Handle<Texture>]) -> bool
Lets go of one hold of the atlas of pages, which
Clips::add_atlas took, and returns whether that was the last:
then the clips it gave that are still here are removed, as
Clips::remove removes one. An atlas that gave no clip, or whose
clips are all gone, is not held: nothing happens.
Sourcepub fn get(&self, handle: Handle<Clip>) -> Option<&Clip>
pub fn get(&self, handle: Handle<Clip>) -> Option<&Clip>
The clip of handle, or None if it was removed.
Sourcepub fn find(&self, name: &str) -> Option<Handle<Clip>>
pub fn find(&self, name: &str) -> Option<Handle<Clip>>
The clip named name, such as sprites/person/walk.
Sourcepub fn name(&self, handle: Handle<Clip>) -> Option<&str>
pub fn name(&self, handle: Handle<Clip>) -> Option<&str>
The name of the clip of handle, if it has one and was not removed.