Hi everybody,
from an example here on Kirupa.com I am trying to figure out how to pan a background.
The example I took explains very well how it works but only with the X coordinate, I added
now an Y-coordinate but because I am still learning to understand Scripting I get into trouble.
With the y-coordinate added to the function triggered by onMouseMove the background will only pan according the second parameter. When I switch the second parameter in the function off in the function the background will work with the first. So far I think that it is not possible to add two parameters this way to the function, but I dont’ know how to solve this. I have a notion where the problem is but I don’t know how to solve it.
Is there a more simple way of doing this? And if not what is the best way to solve this.
here is my actionscript:
this.onMouseMove = function (){
constrainedMove(bg_mc, 10, 1);
constrainedMoveY(bg_mc, 10, 1);
}
function constrainedMove(target:MovieClip, speed:Number, dir:Number) {
var mousePercent:Number = _xmouse/Stage.width;
var mSpeed:Number;
if (dir == 1) {
mSpeed = 1-mousePercent;
} else {
mSpeed = mousePercent;
}
target.destX = Math.round(-((target._width-Stage.width)*mSpeed));
target.onEnterFrame = function() {
if (target._x == target.destX) {
delete target.onEnterFrame;
} else if (target._x>target.destX) {
target._x -= Math.ceil((target._x-target.destX)*(speed/100));
} else if (target._x<target.destX) {
target._x += Math.ceil((target.destX-target._x)*(speed/100));
}
}
}
function constrainedMoveY(target:MovieClip, speed:Number, dirY:Number) {
var mousePercentY:Number = _ymouse/Stage.height;
var mSpeed:Number;
if (dirY == 1) {
mSpeed = 1-mousePercentY;
} else {
mSpeed = mousePercentY;
}
target.destY = Math.round(-((target._height-Stage.height)*mSpeed));
target.onEnterFrame = function() {
if (target._y == target.destY) {
delete target.onEnterFrame;
} else if (target._y>target.destY) {
target._y -= Math.ceil((target._y-target.destY)*(speed/100));
} else if (target._y<target.destY) {
target._y += Math.ceil((target.destY-target._Y)*(speed/100));
}
}
}
thanks in advance