PDA

View Full Version : [AS3] Random 'Shape' generator


airwinds
07-09-2008, 10:05 PM
Hello all,
I was playing this game "Squares 2" ( http://www.ebaumsworld.com/games/play/1073 ) and I was wondering if any of you knew how the random generation of the squares were done in AS3.
I created a class called "Squares", where I defined a random speed, X and Y position and I managed to make one square move across the stage. But how do I keep generating new squares and make them move across?

Thanks!

~Air

stompwampa
07-10-2008, 01:36 AM
Hello all,
I was playing this game "Squares 2" ( http://www.ebaumsworld.com/games/play/1073 ) and I was wondering if any of you knew how the random generation of the squares were done in AS3.
I created a class called "Squares", where I defined a random speed, X and Y position and I managed to make one square move across the stage. But how do I keep generating new squares and make them move across?

Thanks!

~Air

There are a number of ways to do it....i would make a timer for red squared and a timer for black squares. Set the interval to a random number to go off between .1 and 1 seconds.

Every time the timer goes off, create a new square and assign it random x, x and speed values.

Every frame use a FOR loop to sort through the display list and destroy any squares that are outside of a certain boundary in order to save processing speed...

Lather, rinse, repeat.