마우스 커서를 바라보는 액션,
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;
};
두 점을 연결하는 라인을 만드는 메서드 선언
MovieClip.prototype.drawLine = function(x1, y1, x2, y2){
this._x = x1;
this._y = y1;
this._xscale = x2 - x1;
this._yscale = y2 - y1;
};
무비클립을 탄력적으로 움직이게 하는 메서드
// a는 -2부터 2사이의 실수 (-2<a<2)
// b는 -1부터 0사이의 실수(-1<b<0)
// a*a+4b는 -4부터 0사이의 실수(-4<a*a+4b<0)
// b가 -1에 가까울수록 진동폭이 큼
// a가 -2에 가까울수록(작을수록) 속도가 빠름
// tx와 ty는 이동할 최종 위치
MovieClip.prototype.elasticMove = function(a, b, tx, ty){
var tempx = this._x;
var tempy = this._y;
this._x = a*(this._x - tx) + b*(this.prevx - tx) + tx;
this._y = a*(this._y - ty) + b*(this.prevy - ty) + ty;
this.prevx = tempx;
this.prevy = tempy;
};
무비클립을 탄력적으로 확대 및 축소시키는 메서드
// a는 -2부터 2사이의 실수 (-2<a<2)
// b는 -1부터 0사이의 실수(-1<b<0)
// a*a+4b는 -4부터 0사이의 실수(-4<a*a+4b<0)
// b가 -1에 가까울수록 진동폭이 큼
// a가 -2에 가까울수록(작을수록) 속도가 빠름
// txscale와 tyscale는 이동할 최종 위치
MovieClip.prototype.elasticScale = function(a, b, txscale, tyscale){
var tempxscale = this._xscale;
var tempyscale = this._yscale;
this._xscale = a*(this._xscale - txscale) + b*(this.prevxscale - txscale) + txscale;
this._yscale = a*(this._yscale - tyscale) + b*(this.prevyscale - tyscale) + tyscale;
this.prevxscale = tempxscale;
this.prevyscale = tempyscale;
};
무비클립이 (targetX, targetY)로 부드럽게 움직이도록 만드는 메서드
MovieClip.prototype.smoothMove = function(speed, targetX, targetY) {
this._x += speed*(targetX - this._x);
this._y += speed*(targetY - this._y);
};
두 무비클립을 연결하는 메서드
MovieClip.prototype.connectMc = function(mc1, mc2){
this._x = mc1._x;
this._y = mc1._y;
this._xscale = mc2._x - mc1._x;
this._yscale = mc2._y - mc1._y;
};
두 점사이의 거리를 구하는 함수
_global.distance = function(x1, y1, x2, y2){
var diffX = x1 - x2;
var diffY = y1 - y2;
return Math.sqrt(diffX*diffX + diffY*diffY);
}
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;
};
두 점을 연결하는 라인을 만드는 메서드 선언
MovieClip.prototype.drawLine = function(x1, y1, x2, y2){
this._x = x1;
this._y = y1;
this._xscale = x2 - x1;
this._yscale = y2 - y1;
};
무비클립을 탄력적으로 움직이게 하는 메서드
// a는 -2부터 2사이의 실수 (-2<a<2)
// b는 -1부터 0사이의 실수(-1<b<0)
// a*a+4b는 -4부터 0사이의 실수(-4<a*a+4b<0)
// b가 -1에 가까울수록 진동폭이 큼
// a가 -2에 가까울수록(작을수록) 속도가 빠름
// tx와 ty는 이동할 최종 위치
MovieClip.prototype.elasticMove = function(a, b, tx, ty){
var tempx = this._x;
var tempy = this._y;
this._x = a*(this._x - tx) + b*(this.prevx - tx) + tx;
this._y = a*(this._y - ty) + b*(this.prevy - ty) + ty;
this.prevx = tempx;
this.prevy = tempy;
};
무비클립을 탄력적으로 확대 및 축소시키는 메서드
// a는 -2부터 2사이의 실수 (-2<a<2)
// b는 -1부터 0사이의 실수(-1<b<0)
// a*a+4b는 -4부터 0사이의 실수(-4<a*a+4b<0)
// b가 -1에 가까울수록 진동폭이 큼
// a가 -2에 가까울수록(작을수록) 속도가 빠름
// txscale와 tyscale는 이동할 최종 위치
MovieClip.prototype.elasticScale = function(a, b, txscale, tyscale){
var tempxscale = this._xscale;
var tempyscale = this._yscale;
this._xscale = a*(this._xscale - txscale) + b*(this.prevxscale - txscale) + txscale;
this._yscale = a*(this._yscale - tyscale) + b*(this.prevyscale - tyscale) + tyscale;
this.prevxscale = tempxscale;
this.prevyscale = tempyscale;
};
무비클립이 (targetX, targetY)로 부드럽게 움직이도록 만드는 메서드
MovieClip.prototype.smoothMove = function(speed, targetX, targetY) {
this._x += speed*(targetX - this._x);
this._y += speed*(targetY - this._y);
};
두 무비클립을 연결하는 메서드
MovieClip.prototype.connectMc = function(mc1, mc2){
this._x = mc1._x;
this._y = mc1._y;
this._xscale = mc2._x - mc1._x;
this._yscale = mc2._y - mc1._y;
};
두 점사이의 거리를 구하는 함수
_global.distance = function(x1, y1, x2, y2){
var diffX = x1 - x2;
var diffY = y1 - y2;
return Math.sqrt(diffX*diffX + diffY*diffY);
}

