2014-11-14 95 views
0

因此,我正在開發一款遊戲,並試圖創建一個動畫片段來指向鼠標,這個代碼有什麼問題嗎?Actionscript 3對象不轉動

package 
{ 
    import flash.display.*; 
    import flash.events.*; 

    public class Shark extends Sprite 
    { 
     public function Shark() 
     { 

      this.x = 300; 
      this.y = 200; 
      addEventListener(Event.ENTER_FRAME, playGame); 
     } 

     function playGame(event:Event):void 
     { 
      var targetX:int = mouseX - this.x; 
      var targetY:int = mouseY - this.y; 
      this.rotation = Math.atan2(targetY,targetX) * 180/Math.PI; 
     } 
    } 

} 
+0

考慮擴大對您的問題,以更好地闡明你的問題和期望的結果。我沒有看到任何會產生錯誤的東西,但我想這不是你要求的?有些東西不能正常工作嗎?你只是想知道效率嗎? – BadFeelingAboutThis 2014-11-14 22:48:04

回答

2

mouseXmouseY現在相對於對象本身。使用rootmouseXmouseY屬性,而不是像:

var targetX:int = root.mouseX - this.x; 
var targetY:int = root.mouseY - this.y; 
+0

謝謝,我有時候很愚蠢。 – Trows 2014-11-14 22:48:43

+1

@Altrows它發生在每個人身上!很高興能幫助你! – Cherniv 2014-11-14 22:50:39