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

Animating sprite sheets #120

Closed
feelingsonice opened this issue Feb 27, 2024 · 5 comments
Closed

Animating sprite sheets #120

feelingsonice opened this issue Feb 27, 2024 · 5 comments
Labels
question Further information is requested

Comments

@feelingsonice
Copy link

First of all. Thanks for this repo. I just discovered it and it's really well made and saving me a lot of time.

It feels natural to use this to tick the index of a TextureAtlas so I gave it a thought. I'm coming up on some loose ends. Here's what I can gauge:

  • Using Tween to tick the TextureAtlas doesn't feel right since each frame of the index could take varying amounts of time. Tween only takes one duration.
  • String together Tween into Sequence is verbose, and loses some of the functionality of Tween, such as the ability to repeat the sequence as a whole or sending events on completion.
  • It feels natural to use EaseMethod::Discrete for this purpose but the value returned by progress is exclusive, hence you're limited to doing something like EaseMethod::Discrete(0.999), which isn't that bad but feels hacky. This is what I'm coming up against if I were to choose to implement a custom Lens.

Any thoughts on how to use it to tick sprite sheet indices? Is this something you could support?

@feelingsonice
Copy link
Author

I guess the easiest way to do this would be to add some additional methods to Sequence. I'm seeing some others requesting similar features. I'm willing to spend sometime and give it a shot if you think it's doable?

@djeedai
Copy link
Owner

djeedai commented Feb 27, 2024

since each frame of the index could take varying amounts of time

But you can have an indirection in your custom Lens which converts the Tween's linear time into the index of the frame that this time corresponds to, no? I believe you have everything here.

@feelingsonice
Copy link
Author

since each frame of the index could take varying amounts of time

But you can have an indirection in your custom Lens which converts the Tween's linear time into the index of the frame that this time corresponds to, no? I believe you have everything here.

Just to confirm, say if I have an animation with 3 frames, taking 100ms and 200ms between transitions respectively, for a total of 300ms. You are suggesting something like:

Tween::new(
    EaseMethod::Linear,
    Duration::from_millis(600),
    MyCustomLens {
        frames: vec![frame1, fram2, frame3],
        durations: vec![Duration::from_millis(100), Duration::from_millis(200)],
    },
);

Where I'd use the ratio in lerp to determine which frame I'm in. Since Duration::from_millis(600) is twice the duration of the 300ms, this would just be an animation playing at 0.5X the speed?

This is fine except there's now redundancy between the duration given to Tween::new and the set_speed method. A user would need to manually calculate that the duration is 300ms when creating Tween unless they want it sped up.


This aside, I feel like it would be still helpful to have some of the methods on Tween be implemented for Sequence? Especially completion events/callbacks and repeat strategies.

@djeedai
Copy link
Owner

djeedai commented Feb 27, 2024

Where I'd use the ratio in lerp to determine which frame I'm in. Since Duration::from_millis(600) is twice the duration of the 300ms, this would just be an animation playing at 0.5X the speed?

Yes essentially. Except I think it's more common for each frame to have a duration for which it's visible, than to have what looks like inter-frame durations. But that's a detail, depends on what data you have.

This is fine except there's now redundancy between the duration given to Tween::new and the set_speed method. A user would need to manually calculate that the duration is 300ms when creating Tween unless they want it sped up.

Well, you're abusing an animation system (tweening) to play an animation of another type (sprite animation). So yes it's not unexpected to have 2 different time references. But you can always make a helper that will create the proper Tween given a sprite animation, no?

This aside, I feel like it would be still helpful to have some of the methods on Tween be implemented for Sequence? Especially completion events/callbacks and repeat strategies.

Yes. Except that as explained on the relevant issue there's a design question about sequence repeat, which more of less boils down to what happens if you put an infinite tween inside a repeatable sequence? Any tween after the infinite one will never play. But then what happens if you seek from end? All those become edge cases with no intrinsic or expected answer. Not that I don't want to have repeatable sequences; I just can't find a single tangible proposal for it which doesn't fall apart when considering those edge cases.

@djeedai djeedai added the question Further information is requested label Apr 24, 2024
@djeedai
Copy link
Owner

djeedai commented Apr 24, 2024

@feelingsonice any more question or concern or this, or can we close this issue? Did you manage to do what you were trying?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants