2012-02-01 78 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