PDA

View Full Version : relative mouse movement



Ibanez97
February 14th, 2002, 08:25 PM
if (_root._xmouse>_level0.circle._x) {
_level0.circle._x = (_level0.circle._x+10);
} else {
_level0.circle._x = (_level0.circle._x-10);
}


this will make a movie follow the mouse ... how can I make the movie move
the same distance away from the mouse so that the two are lined up in the
middle but as I move the mouse to one side the movie travels and equal
distance to the other side. Any help anyone can give me would be great.

suprabeener
February 15th, 2002, 01:14 AM
in the movie you wish to exhibit this behaviour:


onClipEvent(load){

// where ever the centre is

c = 200;

}



onClipEvent(mouseMove){

_x = c - (_parent._xmouse -c);

}

edit

can be simplified to:
_x = - _parent._xmouse + c;

ilyaslamasse
February 15th, 2002, 04:50 AM
Any particular reason why you use mouseMove instead of enterFrame ??

pom 0]

upuaut8
February 15th, 2002, 04:56 AM
mouse move only checks when the mouse moves. Enter frame checks a number of times per second equal to your frame rate. Less for the processor to handle, I'd guess.

suprabeener
February 15th, 2002, 07:58 PM
exactly upuaut.

in this case, it doesn't make much of a difference, but it's a good practice to run code only when necessary.

Ibanez97
February 18th, 2002, 05:02 PM
I'm not sure I fully understand the code (not real good at this yet) but thanks, it gives me something to work with.

Ibanez97
February 19th, 2002, 08:53 PM
great code, thanks Suprabeener. If you don't mind could you break it down remedial for me? I'm very bad at this. It works for me already but i'm trying to understand it a little better.

suprabeener
February 20th, 2002, 01:47 AM
best way to understand would be to plug in numbers and see why it returns the result it does.

you set c to be the middle so it has something to be relative to, i'm assuming you're all over that. only needs to be done once at the beginning so it goes well in an onClipEvent(load) handler.

everytime the mouse moves we want the movie to react, onClipEvent(mouseMove) fits the bill nicely.

the _x property refers to the x position of whatever's to the left of it. a._x would refer to movie a's x position. but wait, there's nothing to the left of this _x! since code that's not preceded with _root or _level is relative to the clip it's in, that means that _x will refer to whichever clip you place the code in. so we're setting the current clip's _x property.

the _xmouse property refers to the mouse's x position, whatever it may be. this is also a movie property and it's relative to the movie specified just the same way as _x or any other property. this is because each movie has it's own 0,0. so if the mouse is right over movie a's registration point (0,0), a._xmouse will return 0, whereas _root._xmouse will return the mouse's x position relative to _root.

in this case we've specified _parent, which means whichever movie the current movie is in. in this case _root.

so let's say that c was 200, and the mouse is at 268. plug those numbers in...

_x = 200 - (268-200);

lets do the brackets...

_x = 200 - 68;

_x = 132;

so the movie is moved to 132, which happens to be equi-distant from c as the mouse. see how this will always be the case?

fun. fun. fun. ; )

Ibanez97
February 20th, 2002, 12:25 PM
wow, thank you very very much ... that answered all of my questions. Thanks again.

manga101
November 18th, 2003, 04:34 PM
Originally posted by suprabeener
in the movie you wish to exhibit this behaviour:


onClipEvent(load){

// where ever the centre is

c = 200;

}



onClipEvent(mouseMove){

_x = c - (_parent._xmouse -c);

}

edit

can be simplified to:
_x = - _parent._xmouse + c;


sweet..

but how can you stop it so it wont go off stage?... if i move have the MC at right side..

and i move my mouse the MC dissappear ..

jjmancini
July 19th, 2004, 10:16 PM
This is a great little mouse thing...

But... would you know how to imitate this?

Which by the way is an awesome site!

http://www.kelamali.com/La_Bibliotheque_du_Mande.html

Go there and look at some of the pictures.

Notice how the pictures move realtive the mouses position, but in the opposite direction just a few pixels...

Any ideas?

Any help would be awesome!

jjmancini
July 19th, 2004, 10:47 PM
Well, this is what I have so far... but I cannot make the vertical axis move...

Also, I would like to add easing... is that possible?


onClipEvent(load){

// where ever the centre is

c = 200;
d = 150;
}

onClipEvent(mouseMove){

_x = (c) - ((0.02 * _parent._xmouse) - c);
//_y = (d) - ((0.02 * _parent._xmouse) - d);
}


Thanks again!

dmitriysorokin
January 27th, 2009, 08:56 PM
Does that mean that there is no way to move my object if the limit is hit then? Would it be possible for me to obtain the windows cursor position instead then? Or would there be an alternative for obtaining a relative position for movement?