Skip to content

Instantly share code, notes, and snippets.

@Tomyail
Created December 9, 2011 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tomyail/1450965 to your computer and use it in GitHub Desktop.
Save Tomyail/1450965 to your computer and use it in GitHub Desktop.
坐标旋转版圆周运动(包含坐标误差版本和正确版本)
package demo
{
import flash.display.Sprite;
import flash.events.*;
import flash.geom.Matrix;
import flash.geom.Point;
public class FishRoundFly extends Sprite
{
private var fish:Sprite = new Sprite;
// private var centerPoint:Point = new Point;
private var increaseDegree:Number = 1;
private var cos:Number;
private var sin:Number;
private var radias:Number;
private var preX:Number;
private var preY:Number;
private var currentX:Number;
private var currentY:Number;
public function FishRoundFly()
{
fish.graphics.beginFill(0);
fish.graphics.drawRect(0,0,20,20);
addChild(fish);
fish.x = 50
fish.y = 0;
currentX = fish.x;
currentY = fish.y
radias = increaseDegree*Math.PI/180;
cos = Math.cos(radias);
sin = Math.sin(radias);
this.addEventListener(Event.ENTER_FRAME,updateFrame);
this.graphics.lineStyle(1);
}
protected function updateFrame(event:Event):void
{
preX = currentX;
preY = currentY;
currentX = preX * cos - preY * sin;
currentY = preY * cos + preX * sin;
fish.x = currentX;
fish.y = currentY;
this.graphics.lineTo(fish.x,fish.y);
trace("preX",preX,"curX",currentX,"fishX",fish.x);
}
}
}
package demo
{
import flash.display.Sprite;
import flash.events.*;
public class FishRoundFly extends Sprite
{
private var fish:Sprite = new Sprite;
// private var centerPoint:Point = new Point;
private var increaseDegree:Number = 1;
private var cos:Number;
private var sin:Number;
private var radias:Number;
private var preX:Number;
private var preY:Number;
public function FishRoundFly()
{
fish.graphics.beginFill(0);
fish.graphics.drawRect(0,0,20,20);
addChild(fish);
fish.x = 50
fish.y = 0;
radias = increaseDegree*Math.PI/180;
cos = Math.cos(radias);
sin = Math.sin(radias);
this.addEventListener(Event.ENTER_FRAME,updateFrame);
this.graphics.lineStyle(1);
}
protected function updateFrame(event:Event):void
{
preX = fish.x;
preY = fish.y;
fish.x = preX * cos - preY * sin;
fish.y = preY * cos + preX * sin;
this.graphics.lineTo(fish.x,fish.y);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment