Bodom78
December 22, 2002, 11:23am
1
I have a ball that follows the mouse, but I need to confine it to a box shape. I can do it with the dragable buttons but not this MC that follows the mouse.
Here is the code I have attached to the ball MC:
onClipEvent (load) {
_x = 0;
_y = 0;
speed = 5;
}
onClipEvent (enterFrame) {
targetx = _root._xmouse;
targety = _root._ymouse;
}
onClipEvent (enterFrame) {
_x += (targetx-_x)/speed;
_y += (targety-_y)/speed;
}
Cheers.
system
December 22, 2002, 2:09pm
2
Just one more step. Add this AS to the bottem of your AS:
onClipEvent (enterFrame) {
startDrag(getProperty (_x,_y), true, 1, 1, 200, 200);
}
This confines it to a 200 by 200 box.
There’s no need for your 2nd onClipEvent.
onClipEvent (load) {
_x = 0;
_y = 0;
speed = 5;
}
onClipEvent (enterFrame) {
targetx = _root._xmouse;
targety = _root._ymouse;
_x += (targetx-_x)/speed;
_y += (targety-_y)/speed;
}
onClipEvent (enterFrame) {
startDrag(getProperty (_x,_y), true, 1, 1, 200, 200);
}
~Marc
system
December 22, 2002, 11:17pm
3
Excellent, thanks for the help dude
system
December 22, 2002, 11:31pm
4
Well that completely disables the easing code so it doesn’t follow the mouse with easing…
And all of that can be squished down into this simple code…
onClipEvent (enterFrame) {
startDrag(this, true, 1, 1, 200, 200);
}
Produces the same effect.
Now for constraining the easing code, it goes like this…
onClipEvent (load) {
_x = 0;
_y = 0;
speed = 5;
}
onClipEvent (enterFrame) {
targetx = _root._xmouse;
targety = _root._ymouse;
_x += (targetx-_x)/speed;
_y += (targety-_y)/speed;
if (this._x<=1) {
this._x = 1;
}
if (this._x>=200) {
this._x = 200;
}
if (this._y<=1) {
this._y = 1;
}
if (this._y>=200) {
this._y = 200;
}
}
system
December 22, 2002, 11:37pm
5
*Originally posted by Marc *
onClipEvent (enterFrame) {
startDrag(getProperty (_x,_y), true, 1, 1, 200, 200);
}
2 things: getProperty sucks and no need to startDrag on enterFrame, you just do it once (on Load for instance) and it’s enough.
pom
system
December 22, 2002, 11:39pm
6
Yes, getProperty does suck.
And Ilyas… thanks for the info, I always thought startDrag had to go on an enterFrame to update its position. I never tried on Load though.
system
December 23, 2002, 1:10am
7
Thanks for the advice, I learnt a lot there.