rezoner / playground

Playground.js is a framework for your javascript based games. It gives you out-of-box access to essentials like mouse, keyboard, sound and well designed architecture that you can expand to your needs.
MIT License
459 stars 50 forks source link

How to stop current tween? #12

Closed rezoner closed 9 years ago

rezoner commented 9 years ago

First of all app.tween(object)

Creates a new instance of a tween. You can have multiple concurent tweens. So how to stop a tween before running another one?

Method 1

Save reference to a tween and stop it before calling another one.

var current = app.tween(turtle).to({ x: 100, y: 200 }).loop();

/* later in the code you want to call another tween */

current.stop();
app.tween(turtle).to(...);

Method 2

Use .discard() to kill all other tweens attached to the object.

app.tween(turtle).to({ x: 100, y: 200}).loop();

/* later in the code */

app.tween(turtle).discard().to({ x: 200, y: 300}).loop();

/* discard() killed all previous tweens */
luizbills commented 9 years ago

my suggestion: .destroy to discard and destroy. .stop to just stop and .resume to resume.