Here is my code:
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
}
}
For some unknown reason, mouseX and this object’s c change values even when cursor is still (meaning the object flickers)
Here’s the trace, when I leave cursor still:
84 and 80
80 and 84
84 and 80
80 and 84
84 and 80
80 and 84
84 and 80
mouseX isn’t being changed by me (and can’t be since it’s read-only), there isn’t any other code in this object since I’ve only just started with this project.
Thank you.
It seems like your mouseX is based on the clip owning the ‘x’ property you are setting. When you constantly set x to mouseX, this will change the cursor’s position relative to the clip. This is why it oscillates between the two values.
fix: try using the parent clip to get the mouse position, then change the child clip’s position as needed. ie: _parent.mouseX instead of mouseX