Comunidad de diseño web y desarrollo en internet online

rebotar

Citar            
MensajeEscrito el 31 Ago 2009 02:01 am
como hacer rebotar un clip indefinidamente sobre los limites del stage. con actionscript 3

Por torolo2004

1 de clabLevel



 

msie7
Citar            
MensajeEscrito el 31 Ago 2009 05:46 pm
Hola,
aquí te dejo un ejemplo:

Código ActionScript :

//creamos la pelota
var ball:Sprite = new Sprite();
var radius:int = 16;
var g:Graphics = ball.graphics;
g.beginFill(0xFF0000);
g.drawCircle(0, 0, radius);
g.endFill();
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight / 2;
addChild(ball);

//variables para guardar los cuatro bordes del sprite de la pelota
var ballLeft:Number;
var ballRight:Number;
var ballUp:Number;
var ballDown:Number;

//velocidades en las direcciones x e y, que en este ejemplo estarán aleatoriamente entre 0 y 10
var speedX:int = 10 * Math.random();
var speedY:int = 10 * Math.random();

addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(event:Event)
{
   ballLeft = ball.x - radius;
   ballRight = ball.x + radius;
   ballUp = ball.y - radius;
   ballDown = ball.y + radius;
   
   if (ballLeft < 0 || ballRight > stage.stageWidth) speedX *= -1;
   if (ballUp < 0 || ballDown > stage.stageHeight) speedY *= -1;
   
   ball.x += speedX;
   ball.y += speedY;
}

Por isidoro

Claber

498 de clabLevel

2 tutoriales

Genero:Masculino  

firefox

 

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