I’m using the following code to have an MC follow the users mouse based on it’s x value. But I’d like to have this inverted…so that if the users mouse goes right, the MC goes left…instead of going right along with the mouse. You know? How could I do this? I feel it is just one tweek away.
import mx.utils.Delegate;
class Mover {
private var target:MovieClip;
private var limits:MovieClip;
private var ease:Number;
private var leftX:Number;
private var rightX:Number;
private var topY:Number;
private var bottomY:Number;
/*
* Constructor
*
* @param target defines the movieclip to move
* @param limits movieclip used at the limits or bounds for target's movements
*
* @param ease Number that provides the easing on the movieclip. Higher num = ease.
*/
public function Mover(target:MovieClip, limits:MovieClip, ease:Number)
{
this.target = target;
this.limits = limits;
this.ease = (ease != undefined) ? ease : 22;
leftX = limits._x;
rightX = limits._x + limits._width;
}
/*
* Method that starts the animation
*/
public function start():Void
{
target.onEnterFrame = Delegate.create(this, onEnterFrame);
function onEnterFrame():Void
{
var x:Number = Math.min(Math.max(_xmouse, leftX), rightX);
var y:Number = Math.min(Math.max(_ymouse, topY), bottomY);
target._x += (x - target._x) / ease;
target._y += (y - target._y) / ease;
}
}
}