PistonDevelopers / sprite

A library for sprite hierarchy and scene management
MIT License
57 stars 24 forks source link

Add support for sprite animation #8

Open coeuvre opened 10 years ago

coeuvre commented 10 years ago

Now we can change the sprite's texture easily by sprite.set_texture(...). We can manually set the sprite's texture to do animation but we should have a convenient way to do it.

One way in my mind is that we can define a struct Animation to describe the animation which may contain information like:

  1. How many frames does it have?
  2. Which texture(or sub texture) does each frame use?
  3. What the delay between each frames?
  4. Will the animation loop or not? If it will loop, how many times will it loop? or loop forever?
  5. After the animation stopped, which frame will the sprite use?

Once we have the Animation, we can construct an Action for it. So to do animation, the code may look like:

scene.run_action(sprite, Action(Animation(a)));

As we can pause/resume/toggle/stop actions, we can easily pause/resume/toggle/stop animations.

We should focus on this after #6 finished.

Any suggestions?

abonander commented 10 years ago

Animation from GIFs? Is that a good idea?

coeuvre commented 10 years ago

It's a good idea! So we need a library to read GIF format first.

abonander commented 10 years ago

rust-image is a good start. I think it can read animated GIFs but it doesn't have a good API for using them.

bvssvni commented 10 years ago

One idea would be to improve the API or building something on top of it.