2012-02-01 77 views
1

這裏是我的代碼:MouseX值更改時光標仍在

public function update() 
    { 
     //making the character follow the mouse 
     if(mouseX > (x + 25)) 
     { //if the mouse is to the right of mcMain 
      x += mainSpeed;//move mcMain to the right 
     } 
     else if (mouseX < (x - 25)) 
     {//same thing with the left side 
      x -= mainSpeed; 
     } 
     else 
     { 
      trace(x + " and " + mouseX); 
      x = mouseX;//if it's close enough, then make it the same x value 
     } 
    } 

對於一些未知的原因,mouseX這個對象的變化c值甚至當指針仍在(指物體閃爍)

這裏的跟蹤,當我離開光標還是:

84 and 80 
80 and 84 
84 and 80 
80 and 84 
84 and 80 
80 and 84 
84 and 80 

mouseX沒有被我改變了(而不能因爲它的只讀),沒有這個對象,因爲我任何其他代碼我只是從這個開始項目。

謝謝。

回答

4

看起來你的mouseX是基於擁有你正在設置的'x'屬性的剪輯。當您經常將x設置爲mouseX時,這會改變光標相對於剪輯的位置。這就是它在兩個值之間擺動的原因。

修復:嘗試使用父剪輯獲取鼠標位置,然後根據需要更改子剪輯的位置。即:_parent.mouseX代替鼠標X

+0

完美!非常感謝你! – 2012-02-01 03:34:42