Can anybody help me with actionscript?

  • eugehet
  • Born
  • Born
  • eugehet
  • Posts: 2
  • Loc: Singapore

Post 3+ Months Ago

HEy this is the following code for me to generate 1 ball bouncing around the screen randomly . But can anyone tell me how to generate 10 balls all bouncing randomly around the screen?

init();
function init(){



nTop = 60;
nLeft = 12;
nBottom = Stage.height;
nRight = Stage.width;
nVelocityX = 5 ;
nVelocityY = 5;// pixels per frame

mcBall = attachMovie("idball","red",this.getNextHighestDepth());
mcBall._x = 12 + mcBall._width/2;
mcBall._y = 60 + (Stage.height - 60 - mcBall._height/2)/2;
}

function onEnterFrame():Void{
if(mcBall._x > nRight - mcBall._width/2 || mcBall._x < nLeft +
mcBall._width/2){
nVelocityX *= -1;
}
if(mcBall._y < nTop + mcBall._height/2 || mcBall._y > nBottom -
mcBall._height/2){
nVelocityY *= -1;
}
mcBall._x += nVelocityX;
mcBall._y += nVelocityY;

}
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

yea, create 10 balls and use a loop

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 8 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.