PDA

View Full Version : rectangular movement how?



manta
May 26th, 2003, 02:09 PM
Probably a very simple one but I'm puzzling for a while to move a movieclip in a rectangular way with speed control. So the object should move right (400,0) then down (400,400) then from right to left (0,400) and then up again (0,0) and this of course in an endless loop.

I tried this

onClipEvent(enterFrame) {
speed = 1;
this._x += speed;
this._y += speed;

if(this._y>0&&this._y<400){
this._y= 0
}
if(this._x>400){
this._x = 400
}

which works okay, till I get to point (400,0) but then I get stuck, could somebody give me a hint how I should work this simply look math out.

thoriphes
May 26th, 2003, 02:18 PM
onClipEvent (load) {
speed = 10;
xSpeed = speed;
ySpeed = 0;
_x = 0;
_y = 0;
}
onClipEvent (enterFrame) {
_x += xSpeed;
_y += ySpeed;
// upper right corner
if (_x>400 && _y == 0) {
_x = 400;
xSpeed = 0;
ySpeed = speed;
}
// lower right corner
if (_x == 400 && _y>400) {
_y = 400;
xSpeed = -speed;
ySpeed = 0;
}
// lower left corner
if (_x<0 && _y == 400) {
_x = 0;
xSpeed = 0;
ySpeed = -speed;
}
// upper left corner
if (_x == 0 && _y<0) {
_y = 0;
xSpeed = speed;
ySpeed = 0;
}
}

manta
May 26th, 2003, 02:26 PM
thanks thor :)

upuaut
May 27th, 2003, 12:32 AM
u see ^ this?
lol thor

thoriphes
May 27th, 2003, 12:49 AM
hehe...