PistonDevelopers / sprite

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

No way to animate a rectangle/ellipsis #110

Open bgdncz opened 9 years ago

bgdncz commented 9 years ago

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

xaviershay commented 9 years ago

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:

bgdncz commented 9 years ago

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

xaviershay commented 9 years ago

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

bgdncz commented 9 years ago

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

xaviershay commented 9 years ago

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 commented 9 years ago

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.