merwaaan / bevy_spritesheet_animation Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Every sprite entity gets a new material even:
I think this causes the frame rate to drop.
In a similar way to what is done in bevy_sprite3d, https://github.com/FraserLee/bevy_sprite3d/blob/ce57326ff63b1dae99cd2595422672bc82b22325/src/lib.rs#L297-L309, I think we need to use a material cache and return that handle if all of our props match.
It can be done in a separate issue, but if you do go down this path, it would be good to support unlit
and alpha_mode
from the outside, and so from the beginning make those part of the material key.
I haven't tried to change this locally to add a cache, so it's possible this isn't going to help, but even in other Bevy examples where I spawn identical 100 cubes and incorrectly create a new material for every cube I instantly see a frame rate drop. When I change to reuse the same material handle, the frame rate comes back up.
bevy_spritesheet_animation/src/spritesheet.rs
Line 283 in 042a959
Had some issues with this method.
new_clip
. A reference to the library from within the closure would solve that.Fn
method. It should only need to be a FnOnce
.E.g. in
bevy_spritesheet_animation/src/animation.rs
Lines 22 to 27 in 2d16821
Callers rely on reading the docs to see that the duration needs to be milliseconds (mistakes are possibly easier to make, too).
Would it be worth using https://doc.rust-lang.org/std/time/struct.Duration.html? This would make callers look something like:
let clip_id = library.new_clip(|clip| {
clip..set_default_duration(AnimationDuration::PerFrame(Duration::from_millis(100)));
});
(untested).
I know it's more verbose, but it takes the hard-coded millis out of the crate and (arguably) makes the crate less opinionated on the duration format.
By any chance have you created an asset loader that works with this crate?
It's possible that the space is too opinionated at least for this crate to provide an asset loader, but I was curious if you've been using this crate with an asset loader?
I wonder if at the very least we need serde support so we can create clips and animations from RON files, for example? Again, I guess it's possible that is something that this crate should not support and those serialization types and the loader should all be created as 3rd party to this.
I want to be able to create an animation which is made up of a bunch of frames, but which has a number of variants of those same frames.
This is for billboard sprites in a 3D game where each variant is for one of 8 directions.
So if you have a walk animation made up of 3 frames, you want to pick the 3 frames for the current variant.
Calling systems can set the current variant every frame (if they like). For example, a system might update the current variant to match the relative direction of the sprite to the camera^.
I don't think it's possible to use the current features of the crate for one main reason. We need to preserve the existing animation and state rather than asking callers changing the animation_id
or inserting a new animation so that the animation doesn't reset. Imagine a walk animation is playing. If the camera instantaneously rotates, you want the character's same foot to remain on the ground. I.e. you want to keep playing your walk animation, you just want to switch variants.
I am not sure if there's an industry term for this, but I'm using the term variants. Frame sets may also be a term for this, I'm not sure.
Are you interested in working on a design for this with me?
^ Simplified system that updates the sprite's animation variant to correspond with the camera's transform relative to the sprite
fn update_sprite_directions(
// ...
) {
for (mut animation) in q.iter_mut() {
let direction_count = animation.variant_count as f32;
let direction = 0.0 // calculate direction ...
// Callers just need to update the variant they want to show.
animation.current_variant = direction.floor() as usize;
}
}
Currently it does not seem possible to reset animations on an entity (neither reset in-progress animations, nor restart animations that ended). It looks like this could be done by making SpritesheetAnimator
public and adding a reset_animation(entity)
method.
Would love to see this library support Bevy 0.14
!
I am currently using this library to orchestrate a set of directional animations, and it is great at what it does.
I have one question tho, regarding the usage of the library - I'd like to not only change the animation - but also be able to change the frame the animation starts on, this is specifically important for things like bullet animations, where one would maybe want to randomize the starting sprite, or - in my case - the animation of a character rolling, changing the direction of the roll results in the whole animation restarting, which can be quite immersion breaking.
Any ideas how one might be able to solve this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.