Question

I'm trying to animate some bitmaps out in relation to a center point. They don't all start at that center point, but I want them to fly out as though a force from that center point slammed into them and pushed them outwards radially, such that they fly completely off the stage.

So: I know the center point, and the x and y position of each bitmap arranged around it. For each one I can draw a line from the center to that x,y point. I should then be able to get the angle formed by that line to the horizontal, and then set a destination point farther out on that line. The bitmap will be tweened out to that point. I believe that that is what Math.atan2 is for.

Here's what I've got as I iterate through the array of bitmaps (i is an object):

var angle:Number = Math.atan2(i.bitmap.y - centerY, i.bitmap.x - centerX) * 180 / Math.PI;
var dist:Number = 200;              //arbitrary number, just to test
 destX = centerX  + dist * Math.cos(angle);  //destination x
 destY = centerY  + dist * Math.sin(angle);  //destination y

Instead of these things gliding out radially, they're jumping around.

I'm having trouble understanding atan2 and exactly what I'm doing wrong.

Thanks,

David

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top