-
Notifications
You must be signed in to change notification settings - Fork 555
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
added TweenChain #723
base: develop
Are you sure you want to change the base?
added TweenChain #723
Conversation
Hmm, why a separate component, and not an additional capability of "Tween"? It might be worth thinking about whether there's an easy way to abstract the notion of chainable actions out such that you could tie together Animations, Tweens, and any custom-made user events. On the other hand, maybe it's better to just have something that works right now, and abstract that bridge later. |
The way it is implemented right now:
So you would want something like this var ent = Crafty.e("Tween");
// One execution context
ent.tween({x: 100}, 100ms, isSequential = false)
.tween([x: 40, alpha: 0}, 100ms, isSequential = true) // ends after 200ms total
.tween(loopLast = 2) // loop the last two specified tweens
// Another execution context
ent.tween({y: 100}, 100ms, isSequential = true/false?) // pass true or false here? do I know if I'm specifying the first tween in a chain?
// In another scope in the same execution context, ~2ms later
ent.tween([y: 40}, 100ms, isSequential = true) // this will start once the last specified tween finishes rather than something like this var ent = Crafty.e("TweenChain");
// One execution context
ent.tweenChain(relativeValues = false, looping = true, [
[{x: 100}, 100],
[{y: 40, alpha: 0}, 100],
])
// Another execution context
// can't do the same as above - tweens in a chain can not be declared separately right? |
So I have been investigating how the user could reference mulitple chains (e.g. for cancelling them later):
Are you happy with how you define tweens with the |
Yep, matthijsgroen discovered to use promises for chaining actions (either in parallel or sequence) together. See https://groups.google.com/forum/#!topic/craftyjs/DadBdot-NkA. |
For animations, I made a simple component: https://github.com/matthijsgroen/game-play/blob/master/app/scripts/components/generic/TweenPromise.coffee
It simply wraps the tween animation in a promise using WhenJS. And from there I can chain them using sequence, parallel, etc. But since most of this power comes from an external library (WhenJS), and there are different flavours available, I'm not sure if Crafty should solve this problem (since solving it is quite easy) |
I think Bluebird is a noteworthy promise library because it could be used to cancel a chain of promises. I don't know of any other promise library that supports this out-of-the box.
Yeah, agreed, an external, nicely written component is the way to go here. |
TweenChain component:
{x: -2*TILE_WIDTH}
instead of{x: ent.x - 2*TILE_WIDTH}
Example JSFiddle showing 1 TweenChain and 2 other Tweens animating at same time
This feature is listed in the Idea pool - Path Movement and should replace #515
Tests coming after I get the O.K. on the code