Circular movement with rotation
Code Actionscript 2.0
Instance action
onClipEvent (load) {
centerx = 200;
centery = 200;
angle = 0;
radius = 100;
speed = 5;
}
onClipEvent (enterFrame) {
angle = angle - speed;
this._x = centerx + radius * Math.sin(angle * Math.PI / 180);
this._y = centery + radius * Math.cos(angle * Math.PI / 180);
this._rotation = -angle;
}
Code Actionscript 3.0
addEventListener(Event.ENTER_FRAME, enterFrame); var centerx= 200; var centery= 200; var angle= 0; var radius = 100; var speed = 5; function enterFrame(event : Event){ angle= angle- speed; square.x = centerx+ radius * Math.sin(angle* Math.PI / 180); square.y = centery+ radius * Math.cos(angle* Math.PI / 180); square.rotation=-angle; }
Description
This script causes the square to go around in circles. The angle variable is initially set to 0. Upon loading, it is then incrementally increased by the value of the speed variable. The horizontal and the vertical components are calculated from the sine and cosine of the angle. The rotation angle of the square is determined by the angle variable.
related to: Circular movement
Download
Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File