你需要輪動畫實際上是:
createjs.Tween.get(car.wheel,{loop:true,override:true}).to({rotation:"360"}, 1000);
//or
createjs.Tween.get(car.wheel,{loop:true,override:true}).to({rotation:"-360"}, 1000);
更新,根據新的情況:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Example</title>
<script src="https://code.createjs.com/createjs-2015.11.26.min.js"></script>
<script>
function init()
{
var stage = new createjs.Stage("canvas");
createjs.Ticker.setFPS(24); //set some FPS
createjs.Ticker.addEventListener("tick", stage); //set autiomatic refresh
//let's draw something like wheels, with registration point somewhere in the middle :)
var wheels=new createjs.Shape();
wheels.graphics.beginFill("#CCCCCC").drawRect(-100,0,20,50);
wheels.graphics.beginFill("#CCCCCC").drawRect(-100,15,200,20);
wheels.graphics.beginFill("#CCCCCC").drawRect(100,0,20,50);
stage.addChild(wheels);
wheels.x=200;
wheels.y=100;
document.addEventListener("keydown", onKeyDown);
var wheelsInitialRotation=wheels.rotation; //save whells initial rotation
var maximumAngleForRotation=20; //set maximum angle
function onKeyDown(e)
{
var amount;
e = e || window.event;
switch(e.keyCode)
{
//right
case 39:
amount=2;
break;
//left
case 37:
amount=-2;
break;
//all other
default:
amount=0;
}
//check is new angle is not more or less then allowed :)
if(!(wheels.rotation+amount>wheelsInitialRotation+maximumAngleForRotation || wheels.rotation+amount<wheelsInitialRotation-maximumAngleForRotation))
{
wheels.rotation+=amount;
}
}
}
</script>
</head>
<body onload="init();">
<canvas id="canvas" width="400" height="400"></canvas>
</body>
</html>
createjs.Tween.get意味着正在創建一個類? –
TweenJS是CreateJS庫的一部分,它用於動畫,請點擊此處查看:http://www.createjs.com/tweenjs – gMirian
get方法意味着返回一個新的補間實例,並指定您指定的屬性在@gMirian代碼的情況下,'loop'和'override')。 – CrisMVP3200