Skip to main content

Clips

Struct Clips 

Source
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

Source

pub fn new() -> Self

No clips.

Source

pub fn add(&mut self, clip: Clip) -> Handle<Clip>

Adds clip, with no name, and returns its handle.

Source

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.

Source

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.

Source

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.

Source

pub fn get(&self, handle: Handle<Clip>) -> Option<&Clip>

The clip of handle, or None if it was removed.

Source

pub fn find(&self, name: &str) -> Option<Handle<Clip>>

The clip named name, such as sprites/person/walk.

Source

pub fn name(&self, handle: Handle<Clip>) -> Option<&str>

The name of the clip of handle, if it has one and was not removed.

Source

pub fn remove(&mut self, handle: Handle<Clip>) -> Option<Clip>

Removes the clip of handle, and its name, and returns it. Animators that still play it stop where they are; the first such animator in the process logs a warning.

Source

pub fn len(&self) -> usize

How many clips there are.

Source

pub fn is_empty(&self) -> bool

Whether there are none.

Trait Implementations§

Source§

impl Debug for Clips

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Clips

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for Clips

§

impl Freeze for Clips

§

impl Move for Clips

§

impl RefUnwindSafe for Clips

§

impl Send for Clips

§

impl Sync for Clips

§

impl Unpin for Clips

§

impl UnsafeUnpin for Clips

§

impl UnwindSafe for Clips

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.