Skip to content

Instantly share code, notes, and snippets.

@reportbase
Created April 3, 2015 14:42
Show Gist options
  • Save reportbase/dada68b9e6617a85ad30 to your computer and use it in GitHub Desktop.
Save reportbase/dada68b9e6617a85ad30 to your computer and use it in GitHub Desktop.
Eeasel Tweenjs Show bouncing ball
function bouncing_ball2(cnv)
{
var ball = new createjs.Shape();
ball.graphics.setStrokeStyle(5, 'round', 'round');
ball.graphics.beginStroke(('#000000'));
ball.graphics.beginFill("#FF0000").drawCircle(0, 0, 50);
ball.graphics.endStroke();
ball.graphics.endFill();
ball.graphics.setStrokeStyle(1, 'round', 'round');
ball.graphics.beginStroke(('#000000'));
ball.graphics.moveTo(0, 0);
ball.graphics.lineTo(0, 50);
ball.graphics.endStroke();
ball.x = 200;
ball.y = -50;
var tween = createjs.Tween.get(ball, {loop: false})
.to({x: ball.x, y: hubacnv.height - 55, rotation: -360}, 1500, createjs.Ease.bounceOut)
.wait(1000)
.to({x: hubacnv.width - 55, rotation: 360}, 2500, createjs.Ease.bounceOut)
.wait(1000).call(function handleComplete(tween) {var ball = tween._target;})
.to({scaleX: 2, scaleY: 2, x: hubacnv.width - 110, y: hubacnv.height - 110}, 2500, createjs.Ease.bounceOut)
.wait(1000)
.to({scaleX: .5, scaleY: .5, x: 30, rotation: -360, y: hubacnv.height - 30}, 2500, createjs.Ease.bounceOut);
var stage = new createjs.Stage(cnv);
stage.autoClear = true;
stage.addChild(ball);
createjs.Ticker.addEventListener("tick", stage);
}
function bouncing_ball_top(cnv)
{
var w = 600;
if (w >= window.innerWidth - 40)
w = window.innerWidth - 40;
var h = 1000;
if (h >= (getbodyheight() - 40))
h = getbodyheight() - 40;
var x = (window.innerWidth - w)/2;
var ball = new createjs.Shape();
ball.graphics.beginFill("blue").drawRoundRect(0, 0, w, h, 5);
ball.x = x;
ball.y = 0;
var tween = createjs.Tween.get(ball, {loop: false})
.to({x: ball.x, y: (getbodyheight()-h)/2 + loki.dadpage.height, rotation: 0}, 1500, createjs.Ease.bounceOut);
var stage = new createjs.Stage(cnv);
stage.autoClear = true;
stage.addChild(ball);
createjs.Ticker.addEventListener("tick", stage);
}
function bouncing_ball_bottom(cnv)
{
var w = 600;
if (w >= window.innerWidth - 40)
w = window.innerWidth - 40;
var h = 1000;
if (h >= (getbodyheight() - 40))
h = getbodyheight() - 40;
var x = (window.innerWidth - w)/2;
var ball = new createjs.Shape();
ball.graphics.beginFill("blue").drawRoundRect(0, 0, w, h, 5);
ball.x = x;
ball.y = window.innerHeight - h;
var tween = createjs.Tween.get(ball, {loop: false})
.to({x: ball.x, y: (getbodyheight()-h)/2 + loki.dadpage.height, rotation: 0}, 1500, createjs.Ease.bounceOut);
var stage = new createjs.Stage(cnv);
stage.autoClear = true;
stage.addChild(ball);
createjs.Ticker.addEventListener("tick", stage);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment