sprite icon indicating copy to clipboard operation
sprite copied to clipboard

No way to animate a rectangle/ellipsis

Open cuzbog opened this issue 9 years ago • 6 comments

Or maybe it's not documented? I need to animate a Rectangle's opacity and I don't see how that could be done.

cuzbog avatar Sep 07 '15 16:09 cuzbog

Fade a sprite opacity to 0.5 over 2 seconds: scene.run(sprite_id, &Action(FadeTo(2.0, 0.5)))

Not sure best place for documentation, I normally just have the source open. Ref:

  • https://github.com/PistonDevelopers/sprite/blob/master/src/animation.rs#L63
  • https://github.com/PistonDevelopers/sprite/blob/master/src/scene.rs#L98

xaviershay avatar Sep 14 '15 02:09 xaviershay

@xaviershay Yeah, but where do I get the sprite_id?

cuzbog avatar Sep 14 '15 13:09 cuzbog

It's returned from scene.add_child. Here is an example: https://github.com/xaviershay/rust-puzzlefighter/blob/master/src/renderer.rs#L58

xaviershay avatar Sep 14 '15 14:09 xaviershay

@xaviershay Let me rephrase, how do I get a Texture from a Rectangle to create a sprite?

cuzbog avatar Sep 14 '15 17:09 cuzbog

ah I'm sorry, I didn't realise Rectangle was an actual type!! I'm pretty new to the library, was just trying to be helpful :)

Will have a poke around for you tonight.

xaviershay avatar Sep 14 '15 20:09 xaviershay

so looking at things, I don't think this is possible right now since Rectangle isn't implemented as a Sprite with a texture.

To enable this, I think we'd need to have a Sprite trait, and then provide an implementation for ... probably the Contexts in graphics, though I'm not familiar enough with the architecture (either with that heirachy or the relationship between this library and it) there to be sure. Seems like the required implementations should be pretty straightforward.

Perhaps one of the core team can drop in with a better suggestion.

xaviershay avatar Sep 15 '15 00:09 xaviershay