rotateTo(), smoothMove()

Flash - as2, as3 2010. 10. 18. 01:34
// 무비클립을 (targetx, targety)로 회전시키는 함수
MovieClip.prototype.rotateTo = function(targetX, targetY) {
	var diffX = targetX - this._x;
	var diffY = targetY - this._y;
	this._rotation = Math.atan2(diffY, diffX)*180/Math.PI;
}

// 무비클립을 ( targetX, targetY)로 부드럽게 이동시키는 함수
MovieClip.prototype.smoothMove = function(speed, targetX, targetY) {
	this._x += speed*(targetX - this._x);
	this._y += speed*(targetY - this._y);
}

Math.atan2(Math.atan2 메서드)
public static atan2(y:Number, x:Number) : Number
- y/x 점의 각도를 계산하여 라디안 단위로 반환합니다.
- 각도를 측정할 때는 원의 x 축에서부터 반시계 방향으로 측정합니다.
- 0,0은 원의 중심을 나타냅니다.
- 반환값의 범위는 +pi에서 -pi입니다.
: