Groups | Blog | Home
all groups > flash actionscript > june 2006 >

flash actionscript : positioning


Asperon
6/30/2006 7:05:55 PM
ok...say I have dot1(enemy) and I want it to approach the position of
dot2(shield)....how do I do that? I can make dot1(enemy) move to the starting
location of dot2(shield)...but if dot 2(shield) moves dot1(enemy) does not
travel to the new position... this is what I have been using: ( it is inside of
of the dot1(enemy) movie clip):




onClipEvent(enterFrame){
eSpeed = 2;
if(this._x > _root.shield._x){
_x -= eSpeed;
}
if(this._x < _root.shield._x){
_x += eSpeed;
}
if(this._y > _root.shield._y){
_y -= eSpeed;
}
if(this._y < _root.shield._y){
_y += eSpeed;
}
}
kglad
7/2/2006 12:42:23 AM
try:



onClipEvent (enterFrame) {
eSpeed = 2; //<- this doens't need to be repeatedly defined.
var dir = Math.atan2(this._y-_root.shield._y, this._x, _root.shield._x);
this._x += eSpeed*Math.cos(dir);
this._y += eSpeed*Math.sin(dir);
}
AddThis Social Bookmark Button