jueves, 31 de marzo de 2011

ActionScript: Simular gravedad, hacer rebotar una pelota

stage.addEventListener(MouseEvent.CLICK, onClick);
var dy = 20;
var dx = 5
var topey = bola.y;
var topex = bola.x
var gravedad = 1.5;

function onClick(e:Event):void {
   dy = 20;
   addEventListener(Event.ENTER_FRAME, onSalta);
}

function onSalta(e:Event):void {
   bola.x += dx;
   bola.y -= dy
   dy -= gravedad
   if (bola.y > topey) {
      bola.y = topey;
      removeEventListener(Event.ENTER_FRAME, onSalta);
   }
   if (bola.x > stage.stageWidth) {
      bola.x = topex;
   }
}   

 Si gustas el archivo fuente, pulsa aqui.

1 comentario: