Comunidad de diseño web y desarrollo en internet online

un movieclip que siga a otro movieclip

Citar            
MensajeEscrito el 07 Mar 2010 03:06 pm
he tratado tanto yo mismo que ya encontre la forma de crear un movieclip que persiga a otro vea aqui
creen un cuadrito movie clip y pongan esto


Código ActionScript :

onClipEvent (load) {
   speed = 0;
}
onClipEvent (enterFrame) {
   if (Key.isDown(Key.UP)) {
   
   } 
   
   // atras   
   if (Key.isDown(Key.DOWN)) {
      speed -= 1;
      if (Math.abs(speed)>20) {
         speed *= .7;
      }
   }
   
   if (Key.isDown(Key.LEFT)) {
      _rotation -= 15;
      
   } 
   if (Key.isDown(Key.RIGHT)) {
      _rotation += 15;
      
   } 
   speed *= .9;
   x = Math.sin(_rotation*(Math.PI/180))*speed;
   y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
//aqui un movieclip llamado land son los bordes para que no se salga.
   if (!_root.land.hitTest(_x+x, _y+y, true)) {
      _x += x;
      _y += y;
      daños += 1;
   } else {
      car, play();
      speed *= -1;
   }
}


///luego esto en un clip llamado car para perseguirlo

Código ActionScript :

onClipEvent (enterFrame) {
   myRadians = Math.atan2(_root._car._y-this._y, _root.car._x-this._x);
   // Calculates the mouse angle in radians
   myDegrees = Math.round((myRadians*180/Math.PI));
   // Converts the mouse angle to degrees so it can be expressed in _rotation terms
   _root.yChange = Math.round(_root.car._y-this._y);
   // Calculates the distance between the movie clip and the mouse
   _root.xChange = Math.round(_root.car._x-this._x);
   // Calculates the distance between the movie clip and the mouse
   _root.yMove = Math.round(_root.yChange/60);
   // Determines the amount the movie clip should move toward the mouse, grows larger the further the mouse gets from the MC
// si quereis camviar este 60 de acontinuacion dara mas o o menos la velocidad que querais que te persiga.
   _root.xMove = Math.round(_root.xChange/60);
   // See above
   this._y += _root.yMove;
   //Adds yMove onto the position of the clip (Note: Must be '+=' and not '-=' or else the MC will move away from the mouse, not towards it
   this._x += _root.xMove;
   // See above
   this._rotation = myDegrees+90;
   // Turns the MC to face the mouse
}

Por raptor0555

53 de clabLevel



Genero:Masculino  

Desarrollador de juegos

firefox
Citar            
MensajeEscrito el 07 Mar 2010 03:46 pm
Wow, impresionante, animo, luego nos lo presumes :D

Por holler

65 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 08 Mar 2010 10:54 am
ok pero ponganme alguna referencia para subir un ejemplo que no se subir ejemplos

Por raptor0555

53 de clabLevel



Genero:Masculino  

Desarrollador de juegos

firefox
Citar            
MensajeEscrito el 08 Mar 2010 10:56 am
el nombre esta alreves el primer movieclip es el que se llamara car en el nombre de instancia el segundo no tendra nombre de instancia

Por raptor0555

53 de clabLevel



Genero:Masculino  

Desarrollador de juegos

firefox

 

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