This article explain you how to create an object which rotate around the center continiously. In this tutorial you will learn more about the center and math, sine/cos/degrees/radians. Here I am going to explain you with the action script:
First Create an object of any shape which you want to rotate around the circle. And give a instance name for the object. In this example I have used a circle shape having circ instance name & I will describe you using the same instance name in this tutorial.
Here I want to start right now. First I will divide the stage from X & Y by 2 show that I can find the center position of the stage.
circ.centerX = Stage.width / 2;
circ.centerY = Stage.height / 2;
Now set the starting point on the circle, in degrees.
circ.angle = 0;
Define the radius of the circle.
circ.radius = 100;
Here I declare the amount of change in the angle (You know angle change will be in degree) for each iteration of the animation. Here I have used 20 degree for angle change. This will effect the rotation speed. If you need to increase speed you should increase angleChange and decrease for low speed.
circ.angleChange = 10;
Now write a function to convert degrees to radians. This function accepts degrees and returns radians.
function degreetoradian(degree) {
return degree * (Math.PI / 180);
}
Ok We got the radians.
Now I start AS to rotate the circle.
function animateCircle() {
Here I store the radian conversion of the degree
var radian = degreetoradian(this.angle);
Now set the x and y cordinate for this movieClip, based on the clip-specific. And variables storing the circle center and radius, determining x and y coordinates using cosine and sine, respectively.
this._x = this.centerX + this.radius * Math.cos(radian);
this._y = this.centerY + this.radius * Math.sin(radian);
Here I add the angle change to the master angle for this clip with each iteration, so we know how to determine the next x,y point.
this.angle += this.angleChange;
And now modulus to determine the correct angle for any angle which is greater than 360-degrees.
this.angle+= 3;
}
You can give required value for angle change.
And in the final assign a funcion to be called on every EnterFrame event for this clip to play movie continiously.
circ.onEnterFrame = animateCircle;
The Action Script Code:
//Define the stage for orbit and finding the center.
circ.centerX = Stage.width / 2;
circ.centerY = Stage.height / 2;
//Define the starting anlge point on the circle, in degrees.
circ.angle = 0;
//Set the radius of the circle
circ.radius = 110;
//Set the angle change amount value.
circ.angleChange = 10;
//function to convert degrees to radians
function degreetoradian(degree) {
return degree * (Math.PI / 180);
}
//Create function to animate circle
function animateCircle() {
//use a local variable to store the radian conversion of the degree
// value more familiar to most of us. See notes on Flash angles.
var radian = degreetoradian(this.angle);
//set the x and y cordinate for this slip, based on the clip-specific
// variables storing the circle center and radius. See notes for
// determining x and y coordinates using cosine and sine, respectively.
this._x = this.centerX + this.radius * Math.cos(radian);
this._y = this.centerY + this.radius * Math.sin(radian);
//add the angle change to the master angle for this clip with each
// iteration, so we know how to determine the next x,y point.
this.angle += this.angleChange;
//use modulus to determine the correct angle for any angle greater
// than 360-degrees. See notes for an explanation of modulus.
this.angle+= 3;
}
//Now animate circle on onEnterFrame
circ.onEnterFrame = animateCircle

RSS Feeds
Feed Comment 




Leave Your Comments Below