-
Moving movie clip across stage?
Hey,
How would I move a movie clip from a (non-specified) point, to a designated destination (in coordinates)?
For example, move a movie clip named "Guy" to coordinates X=100, Y=100.
Thanks in advance!
-
Whoops...
I read that again, and realized I forgot to mention something...
I need it to move progressively, not instantly.
Like, scoot across the screen, instead of just appearing there.
Thanks!
-
You can have velocity variables like vX and vY. Probably inside a timer event or enter frame, have your movie clip (mc) coordinates updated. Something like this:
Actionscript Code:
var vX:uint = 2; var vY:uint = 3;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(e:Event):void { //your movie clip's position mc.x += vX; mc.y += vY;
//stop the movement when your movie clip reaches the position if (mc.x >= 100) { vX = 0; } if (mc.y >= 100) { vY = 0 } }
Last edited by flashmed; 08-05-2011 at 09:01 AM.
-
I'd use a tweening engine like TweenLite, where you'd do something like:
Code:
TweenLite.to(mc, 1, {x:100, y:100});
But you can do this yourself, too.
Code:
var destination:Point = new Point(100, 100);
var steps:int = 100; //how many frames to get there.
var dx:Number = (destination.x - mc.x) / steps;
var dy:Number = (destination.y - mc.y) / steps;
mc.addEventListener(Event.ENTER_FRAME, nudge);
function nudge(e:Event):void{
mc.x += dx;
mc.y += dy;
if (mc.x == destination.x){
mc.removeEventListener(Event.ENTER_FRAME, nudge);
}
}
-
Thank you both, I got it!
Flashkit never lets me down
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|