CanvasScript3
>
Tests
> Tween - Yoyo
Code
var stage = new Stage("canvas", 420, 500, 30); var colors = [0xcc0000, 0xffcc00, 0xaaff00, 0x0099cc, 0x194c99, 0x661999]; var funcs = ['Linear', 'Back', 'Bounce', 'Circ', 'Cubic', 'Elastic', 'Quad', 'Quart', 'Quint', 'Sine']; var cnt = 0; var createBox = function() { var box = new Shape(); box.y = (cnt++ * 15); box.graphics.beginFill(colors[Math.floor(Math.random() * colors.length)]); box.graphics.drawRect(0, 0, 15, 15); box.graphics.endFill(); stage.addChild(box); return box; } var createTween = function(obj, func) { var tween = new Tween(obj, 'x', func, 0, 405, 60, false); tween.addEventListener(TweenEvent.MOTION_FINISH, tween.yoyo); obj.addEventListener(Event.REMOVED_FROM_STAGE, function(e) { tween.removeEventListener(TweenEvent.MOTION_FINISH, tween.yoyo); tween.stop(); }); return tween; } for (n in funcs) { createTween(createBox(), Tween[funcs[n]].easeIn); createTween(createBox(), Tween[funcs[n]].easeOut); createTween(createBox(), Tween[funcs[n]].easeInOut); }
Canvas
Output