View Full Version : A Movie Clip Moving where clicked
Bobguy
12-21-2005, 12:54 PM
How would i make it where ever i click on the screen, the MC will move there? Thanks in advance
clickSpot_x = _x;
clickSpot_y = _y;
onClipEvent (mouseUp) {
if (_currentframe == 1 && _root._ymouse < 340) {
clickSpot_x = _root._xmouse;
clickSpot_y = _root._ymouse;
}
}
Try something like that
Steven
12-21-2005, 01:56 PM
This is what I would do. Make a movie clip and put this code on it:
onClipEvent (load) {
targx = 240;
targy = 160;
speed = 10;
}
onClipEvent (mouseDown) {
targx = _root._xmouse;
targy = _root._ymouse;
}
onClipEvent (enterFrame) {
gotoX = targx;
gotoY = targy;
delta_x = this._x-gotoX;
delta_y = this._y-gotoY;
targRot = -Math.atan2(delta_x, delta_y)/(Math.PI/180);
this._rotation = targRot;
if (Math.sqrt((delta_x*delta_x)+(delta_y*delta_y))>speed) {
this._y -= speed*Math.cos(this._rotation*(Math.PI/180));
this._x += speed*Math.sin(this._rotation*(Math.PI/180));
}
if (this._y<40) {
this._y = 40;
}
if (this._y>280) {
this._y = 280;
}
if (this._x<40) {
this._x = 40;
}
if (this._x>440) {
this._x = 440;
}
}
As simple as that.
Freddy
12-21-2005, 02:01 PM
or do it the simple man's way.
onClipEvent(mouseUp){
this._x = _xmouse;
this._y = _ymouse;
}
should work like a cham.
bactac
12-21-2005, 02:15 PM
onClipEvent(mouseUp){
this._x = _root._xmouse;
this._y = _root._ymouse;
}
Corrected.
Freddy
12-21-2005, 02:24 PM
-_-
=/
smart ass
=P
you dont need _root. for it lol.
but still.
Bobguy
12-21-2005, 08:07 PM
I should of explained it better, I want it to move not just appear where the mouse is clicked, like how steven did it, but i dont want it to rotate, i tried playing with the code couldnt figure out how to make it not rotate, thanks
Soon to be flash master
12-21-2005, 08:13 PM
like on mother load?
Bobguy
12-21-2005, 08:55 PM
kind of like the flying part of mother load, but i want it to just automaticly go where you clicked, not having to hold it
arkhan
12-22-2005, 04:33 AM
onClipEvent (load) {
targx = 240;
targy = 160;
speed = 10;
}
onClipEvent (mouseDown) {
targx = _root._xmouse;
targy = _root._ymouse;
}
onClipEvent (enterFrame) {
gotoX = targx;
gotoY = targy;
delta_x = this._x-gotoX;
delta_y = this._y-gotoY;
targRot = -Math.atan2(delta_x, delta_y)/(Math.PI/180);
if (Math.sqrt((delta_x*delta_x)+(delta_y*delta_y))>speed) {
this._y -= speed*Math.cos(targRot*(Math.PI/180));
this._x += speed*Math.sin(targRot*(Math.PI/180));
}
if (this._y<40) {
this._y = 40;
}
if (this._y>280) {
this._y = 280;
}
if (this._x<40) {
this._x = 40;
}
if (this._x>440) {
this._x = 440;
}
}
wont rotate now..
Bobguy
12-22-2005, 12:28 PM
thank you very much
Grunteh
12-22-2005, 12:29 PM
Thats a long code.
A long code, as usual without an explanation. How hard is it to give one?
Bobguy
12-23-2005, 05:31 PM
hmmm, when ever I test it, the MC always movies up in the begining, any way to fix it?
thats cuse thats where you clicked.
Bobguy
12-23-2005, 06:01 PM
no when i press crtl + enter they, automaticly move with out me clicking
The Brown Cow
12-23-2005, 06:18 PM
The code sets the target to a point when it starts.
This bit:
onClipEvent (load) {
targx = 240;
targy = 160;
speed = 10;
}
Just set targx and targy to the location of your clip.
You could use:
onClipEvent (load) {
targx = _x;
targy = _y;
speed = 10;
}
Bobguy
12-23-2005, 06:23 PM
thanks alot brown cow! =D
arkhan
12-23-2005, 10:28 PM
I didnt really read the code XD...he said it was working I cuted off the _rotation part
vBulletin® v3.7.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.