Comunidad de diseño web y desarrollo en internet online

Algo que siga al cursor...

Citar            
MensajeEscrito el 21 Dic 2008 02:22 pm
Quería saber como hacer que una pelotita que siga al cursor, si lo toca le saca vida, pero eso ya lo hice...

Por Juaniix

85 de clabLevel



 

firefox
Citar            
MensajeEscrito el 21 Dic 2008 03:21 pm
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();


Queda un efecto muy cool. :D

Por JaLeRu

Claber

1913 de clabLevel

7 tutoriales

Genero:Masculino  

Existo

firefox
Citar            
MensajeEscrito el 21 Dic 2008 05:04 pm
AS2.0

Por Juaniix

85 de clabLevel



 

firefox
Citar            
MensajeEscrito el 21 Dic 2008 05:10 pm
Mira, en el nivel "suicide time" quiero que la bola "drogada" xD 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); )

Por Juaniix

85 de clabLevel



 

firefox
Citar            
MensajeEscrito el 21 Dic 2008 05:18 pm
var Speed:Number = 10 // Velocidad del personaje
var TmpXY:Number = 0;

onEnterFrame = function() {
gotoSpotX = this._parent._xmouse;
gotoSpotY = this._parent._ymouse;

// 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...

Por Juaniix

85 de clabLevel



 

firefox
Citar            
MensajeEscrito el 21 Dic 2008 06:19 pm
Mi código es traducible fácilmente a As2.
Debes poner esto dentro de algún EnterFrame....

Código ActionScript :

var ang=Math.atan2(_ymouse-pelotita._y,_xmouse-pelotita._x); 
pelotita._x+=Math.cos(ang)*2; 
pelotita._y+=Math.sin(ang)*2; 
 

Debería funcionar. pelotita es la instancia de el MC que sigue al mouse.

Por JaLeRu

Claber

1913 de clabLevel

7 tutoriales

Genero:Masculino  

Existo

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.