javascript - How can I use tweenJS make bitmap move to some points -
i meet question this:
i want make bitmap move points, stored in array. how can use tweenjs this?
i try first method this:
var points = [{x:0, y:0}, {x:100, y:100},{x:200, y:200}]; //the points come other method, , data points. for( var i=0; < points.length; i++ ) { createjs.tween.get( target ) .to( { x: points[i].x, y: points[i].y }, 600, createjs.ease.easein); }
running code, target move first point.so give up.
then try second method :
var str = 'createjs.tween.get( target )'; for( var i=0; < points.length; i++ ) { str += '.to( { x: points[' + + '].x, y: points[' + + '].y }, 600, createjs.ease.easein)' } eval( str );
it works perfect, worry "eval" , not safe. can give me tips ? big hug.
just tween once, , add each to
in loop. sample creates multiple tweens run concurrently:
var points = [{x:0, y:0}, {x:100, y:100},{x:200, y:200}]; var tween = createjs.tween.get( target ); // once, outside loop for( var i=0; < points.length; i++ ) { // add each to() call current tween (chains them) tween.to( { x: points[i].x, y: points[i].y }, 600, createjs.ease.easein); }
that should it.
Comments
Post a Comment