2017-07-27 237 views
0

正在使用Adobe Animate CC(HTML5)製作停車場項目。 我已經進入我的畫布汽車和它的車輪。通過下面的命令,我可以通過按下鍵盤箭頭左右旋轉車輪。Createjs中的最大旋轉(adobe animate cc)

document.onkeydown = keyHandler.bind(this); 
function keyHandler(event) { 

var e = event||window.event; 
//left 
if(e.keyCode == 37) { 
    this.car.wheels3.rotation-=2; 

但我想使其在一定的旋轉比旋轉,像汽車rotates.I想我必須作出一個方法的實際輪,但我不知道如何使用旋轉屬性與方法我想創造。任何想法/幫助表示讚賞。

回答

0

你需要輪動畫實際上是:

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> 
+0

createjs.Tween.get意味着正在創建一個類? –

+0

TweenJS是CreateJS庫的一部分,它用於動畫,請點擊此處查看:http://www.createjs.com/tweenjs – gMirian

+0

get方法意味着返回一個新的補間實例,並指定您指定的屬性在@gMirian代碼的情況下,'loop'和'override')。 – CrisMVP3200

相關問題