0
votes

I have 7 movieclips on stage I want to tween around an ellipse from different start points. I am having lots of trouble doing this.... I used a circle formula at first and then divided the y value by the width of the ellipse over the height. This sort of worked but after every rotation the y value was a little of. That code is:

this._x += (Math.cos(angle * Math.PI/180) * radius); this._y += (Math.sin(angle * Math.PI/180) *radius)/1.54;

I also have trouble finding the angle of the start point, if it is off they won't travel in the same ellipse but they all have different starting angles.

Any clues?

2
I don't really understand the part about the angles, do you want them evenly spaced?grapefrukt
Yep and the angle of the ellipse is different at each point, I need to find the angle of where each point is so I know where to start it off in the equation. Does that make any sense?George Reith

2 Answers

2
votes

Calculate the incidvidual offsets using this snippet:

// assuming you have your buttons in an array called buttons
for (var i:Number = 0; i < buttons.length; i++){
    buttons[i].angleOffset = 360 / buttons.length * i;
}

Set the position each update instead of moving, that way you wont get any drift. Update each object using this code, incrementing the angle var to get it to spin.

    this._x = offsetX + Math.sin((angle + angleOffset) * Math.PI/180) * radius; 
    this._y = offsetY + Math.cos((angle + angleOffset) * Math.PI/180) * radius / 1.54;
0
votes

This is almost soved, this piece of script will take the items of the array buttons (can add as many as you want), space them around the ellipse you set (origin + radius), and tween them around it according to the speed you set. The only problem is the spacing isn't even and some are close and some far apart and I don't understand why.

var angle:Number = 0;
var originX:Number = 200;
var originY:Number = 200;
var radiusX:Number = 267.5;
var radiusY:Number = 100;
var steps:Number = 360;
var speed:Number = 3.1415/steps;
var buttons:Array = new Array(this.age,this.ethnicity,this.sex,this.social,this.ability,this.orientation,this.faith);

for (i=0;i<buttons.length;i++) {
buttons[i].onEnterFrame = function() {
    moveButtons(this);
    controllButtons(this);
};
buttons[i]._order = (360/buttons.length) * (i+1);
}
function moveButtons(e) {
    e._anglePhase = angle+e._order;
    e._x = originX+Math.sin(e._anglePhase)*radiusX;
    e._y = originY+Math.cos(e._anglePhase)*radiusY;
}

function controllButtons(e) {
    angle += speed;
    if (angle>=360) {
        angle -= 360;
    }
}

Please note I got the base of this script from http://www.actionscript.org/forums/showthread.php3?t=161830&page=2 converted it to AS2 and made it work from an array.