[RESOLVED] Another parallax question... confining movement
Hi,
I have the script below which controls three movieclips on different layers to scroll up/down/left/right depending on the mouse position. These three layers are visible within a frame. The effect works nicely, except that there are no constraints to stop the movieclips scrolling infinitely.
How do I make it so that the moviclips edges never come into view... i.e. the scrolling stops when the edge of the background clip touches the edge of the frame?
Actionscript Code:
var verticalCenter:Number = Stage.width/2;
var horizontalCenter:Number = Stage.height/2;
function parallax (layer, speed) {
if (mask2.hitTest(_xmouse,_ymouse,true)) {
var distanceX = _root._xmouse-verticalCenter;
var distanceY = _root._ymouse-horizontalCenter;
if (_xmouse > verticalCenter) {
layer._x -= distanceX*speed;
} else {
layer._x += distanceX*-speed;
}
if (_ymouse > horizontalCenter) {
layer._y -= distanceY*speed;
} else {
layer._y += distanceY*-speed;
}
}
}
trees1.onEnterFrame = function() { parallax(this, 1/40); }
trees2.onEnterFrame = function() { parallax(this, 1/60); }
trees3.onEnterFrame = function() { parallax(this, 1/80); }
Many thanks for any input!
:)