Ver Mensaje Individual
  #6 (permalink)  
Antiguo 11/05/2011, 15:19
Avatar de esdebon
esdebon
 
Fecha de Ingreso: agosto-2008
Ubicación: México
Mensajes: 167
Antigüedad: 15 años, 9 meses
Puntos: 18
Respuesta: problemas con direccion de la animacion

Condiciones:

- Las carpas deben estar en el centro de su movieClip.

- Procura que tu funcion aleatorio() de un valor dentro de la pecera, si no se traban los peces.

Código actionscript:
Ver original
  1. var k_01 = new koi();
  2.     k_01.x = aleatorio(0,181);
  3.     k_01.y = aleatorio(0,181);
  4.     k_01.velx = aleatorio(1,5);
  5.     k_01.vely = aleatorio(1,5);
  6.     k_01.dirx = (1-(Math.floor(Math.random()*2)*2));
  7.     k_01.diry = (1-(Math.floor(Math.random()*2)*2));
  8.     addChild(k_01);
  9. var k_02 = new koi2();
  10.     k_02.x = aleatorio(0,181);
  11.     k_02.y = aleatorio(0,181);
  12.     k_02.velx = aleatorio(1,5);
  13.     k_02.vely = aleatorio(1,5);
  14.     k_02.dirx = (1-(Math.floor(Math.random()*2)*2));
  15.     k_02.diry = (1-(Math.floor(Math.random()*2)*2));
  16.     addChild(k_02);
  17. var k_03 = new koi3();
  18.     k_03.x = aleatorio(0,181);
  19.     k_03.y = aleatorio(0,181);
  20.     k_03.velx = aleatorio(1,5);
  21.     k_03.vely = aleatorio(1,5);
  22.     k_03.dirx = (1-(Math.floor(Math.random()*2)*2));
  23.     k_03.diry = (1-(Math.floor(Math.random()*2)*2));
  24.     addChild(k_03);
  25.    
  26.  
  27. k_01.addEventListener(Event.ENTER_FRAME, mover)
  28. k_02.addEventListener(Event.ENTER_FRAME, mover)
  29. k_03.addEventListener(Event.ENTER_FRAME, mover)
  30.  
  31. var limiteDerecho:Number=stage.stageWidth;
  32. var limiteIzquierdo:Number=0;
  33. var limiteArriba:Number=0;
  34. var limiteAbajo:Number=stage.stageHeight;
  35.  
  36. function mover(e:Event):void
  37. {
  38.     e.target.x+= e.target.velx * e.target.dirx;
  39.     e.target.y+= e.target.vely * e.target.diry;
  40.     if(e.target.dirx<0){
  41.         e.target.scaleX=-1;
  42.     }else{
  43.         e.target.scaleX=1;
  44.     }
  45.     ///////////Limites
  46.     if((e.target.x+e.target.width/2)>limiteDerecho || (e.target.x-e.target.width/2)<=limiteIzquierdo){
  47.         e.target.dirx*=-1;
  48.     }
  49.     if((e.target.y+e.target.height/2)>limiteAbajo || (e.target.y-e.target.height/2)<=limiteArriba){
  50.         e.target.diry*=-1;
  51.     }  
  52. }
__________________
Mi sitio: http://www.fluocode.com