Hey
I have this little file I’m working on at the moment where a ball is rotating around an oval shape. This works and is looking good. What I want to do now is to create 3 more instances of the ball sprite and I’ve created and position them in the other 3 corners of the oval.
So it looks sort of like this to start off with:
----o
o ----- o
----o
(ignore the dashes, I just put them in there to I could illustrate the ‘4 corners’)
I want all the balls to follow the same path and same speed etc. I’m assuming that there is some simple math formula I need to know but it’s sort of going over my head at the moment.
Here’s the code I’m working on:
package {
import flash.display.Sprite;
import flash.events.Event;
public class Oval extends Sprite {
private var ball:Ball;
private var ball2:Ball;
private var angle:Number = 0;
private var centerX:Number = 200;
private var centerY:Number = 200;
private var radiusX:Number = 200;
private var radiusY:Number = 100;
private var speed:Number = .1;
public function Oval() {
init();
}
private function init():void {
ball = new Ball();
addChild(ball);
ball.x = 0;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
ball.x = centerX + Math.sin(angle) * radiusX;
ball.y = centerY + Math.cos(angle) * radiusY;
angle += speed;
}
}
}
I’ve included the files I’ve been working on so you can see.
Any help would be greatly appreciated.
Cheers!