Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement sprite animations #15511

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

s-puig
Copy link
Contributor

@s-puig s-puig commented Sep 28, 2024

WIP. Posting this to see if this is wanted or should be a third-party crate.

Objective

  • Implement sprite animation

Solution

  • Determines the sprite index based on time since animation start at the end of every frame.

Testing

Unit tested the player. They are of questionable code quality but should be accurate.
Still missing quite a few though


Showcase

SpriteClip basics
let clip = SpriteClip {
        // Clip frames also accepts Handle<Image> for people who don't want to deal with atlases
        clip: ClipFrames::from([0, 1, 2, 3, 4, 5, 6]),
        speed: 1.0,
        // number of frames per second
        fps: 1,
        // Also has Repeat(usize)
        clip_loop: ClipLoopMode::Infinite,
    };

// Clip is an asset so you can change the behaviour of an animation for all entities and load them via asset_server
let clip = asset_server.add(clip);
// Clips can easily be overwritten without affecting the underlying asset
let overwritten_clip = clip.clone().overwrite().backward().fps(2));
SpriteAnimationPlayer basics
// It uses SpriteAnimationPlayer component
let mut player = SpriteAnimationPlayer::default(); //all fields are public but it might be more convenient to use new or default
// and are added like any other component
commands.spawn((
        SpriteBundle,
        TextureAtlas,
        player,
    ));
// Players are also assets
let player_asset = asset_server.add(player);
// and can be added to entities allowing synced animations (useful for stuff like trees and water)
commands.spawn((
        SpriteBundle,
        TextureAtlas,
        player_handle,
    ));
// Player has the expected methods
player.play(clip.clone().overwrite().backward().fps(2));
player.stop();
player.resume();
player.restart();
// Transitions can be configured (WIP)
player.play_with_transition(clip, TransitionMode::AnimationEnd);

@alice-i-cecile
Copy link
Member

Strong yes please to upstreaming this. Very overdue.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Animation Make things move and change over time X-Controversial There is active debate or serious implications around merging this PR C-Needs-Release-Note Work that should be called out in the blog due to impact S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Sep 28, 2024
Copy link
Contributor

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

@BenjaminBrienen BenjaminBrienen added the D-Complex Quite challenging from either a design or technical perspective. Ask for help! label Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Animation Make things move and change over time C-Feature A new feature, making something new possible C-Needs-Release-Note Work that should be called out in the blog due to impact D-Complex Quite challenging from either a design or technical perspective. Ask for help! S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants