Skip to content

Instantly share code, notes, and snippets.

@bgadrian
Created March 16, 2015 17:13
Show Gist options
  • Save bgadrian/e910da1fb527dd50077e to your computer and use it in GitHub Desktop.
Save bgadrian/e910da1fb527dd50077e to your computer and use it in GitHub Desktop.
tweenJS modify a JS object
// Each time score is added, tween the value.
function addScore(score) {
// Save the new score
this.newScore = score;
// Create a tween that will update the "displayScore", which
// we use to display the changing number.
var tween = createjs.Tween.get(this).to({displayScore:score}, 800);
// For this example, set a local "scope" so the onChange
// callback has something to refer to.
var scope = this;
// As the tween runs, it will call "onChange"
tween.onChange = function(tween) {
// Update the text instance with "displayScore".
scope.text.text = scope.displayScore;
}
}
// The "ScoreManager" abstracts the score formatting and tweening.
function killEnemy(points) {
this.scoreManager.addScore(points);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment