flash - How do I play an animation in a specific place controlled by actionscript? -
i have moving character , when press button want shoot @ object pointed mouse. character moving don't know how make animation in specific place. using flash, actionscript 2 or 3
there many ways in can done, 1 known 1 of simplest:
given source point , target point b:
calculate distance between , b
var distance:number = computedistance(a,b); //define function computedistance returns pythagorean distance between , b
calculate x , y difference
var dx:number = b.x - a.x; var dy:number = b.y - a.y; // normalization. think of ratio of legs relative hypotenuse dx = dx / distance; dy = dy / distance;`
calcualate xspeed , yspeed multiplying dx
, dy
speedperframe
(arbitrary)
var xspeed:number = dx*speedperframe; var yspeed:number = dy*speedperframe;
increment object's x
, y
position using xspeed
, yspeed
in main game loop (respectively). make sure add check if object has arrived @ destination point.
Comments
Post a Comment