ok, es simple. Pero primero especificame que lenguaje. As2 o As3? En As3:
Código ActionScript :
var Fresh:Timer=new Timer(10);
Fresh.addEventListener(TimerEvent.TIMER, onFresh);
function onFresh(e:TimerEvent){
var ang=Math.atan2(mouseY-pelotita.y,mouseX-pelotita.x);
pelotita.x+=Math.cos(ang)*2;
pelotita.y+=Math.sin(ang)*2;
}
Fresh.start();
Mira, en el nivel "suicide time" quiero que la bola "drogada" siga al cursor sin detenerse, ya lo hice, pero en una parte vuelve a un lugar y no se porque razón, el nivel dura 5 segundos... ( pauseTimeline(5000); )
// calculate angle of current position to target position delta_x = this._x-gotoSpotX; delta_y = this._y-gotoSpotY; targetRotation = -Math.atan2(delta_x, delta_y)/(Math.PI/180); if (targetRotation<0){ targetRotation += 360//Acomoda el angulo para que sea de 360 grados }
// move beetle toward the target and stop when it gets there if (Math.sqrt((delta_x*delta_x)+(delta_y*delta_y))>Speed) { _y -= Speed*Math.cos(targetRotation*(Math.PI/180)); _x += Speed*Math.sin(targetRotation*(Math.PI/180)); this.Fachadas.Parado = false; //Controla fachada de estar parado }else{ this.Fachadas.Parado = true; }
// // loop to opposite side of the masked area when the beetle travels off-screen if (_y<0) { _y = 400; } if (_y>400) { _y = 0; } if (_x<0) { _x = 400; } if (_x>400) { _x = 0; }
// Asigna el cambio de fachadas if (targetRotation<45){ this.Fachadas.Angulo = 0; }else if (targetRotation<90){ this.Fachadas.Angulo = 45; }else if (targetRotation<135){ this.Fachadas.Angulo = 90; }else if (targetRotation<180){ this.Fachadas.Angulo = 135; }else if (targetRotation<225){ this.Fachadas.Angulo = 180; }else if (targetRotation<270){ this.Fachadas.Angulo = 225; }else if (targetRotation<315){ this.Fachadas.Angulo = 270; }else if (targetRotation<360){ this.Fachadas.Angulo = 0; } }
Esto sigue al cursor, pero se vuelve al mismo lugar de donde salió en unos segundos...