Reputation: 11
What is the best way of generating a pattern outside of the stage with actionscript 3? I am trying to create an endless flight of stairs which the user is moving along. The first set of steps is drawn at run-time using:
for(i=0; i<40 ; i++)
{
var _block:Platform=new Platform("Platform",{x:i*20 ,y: 400 - i * 20, view:"../assets/art/step.png"});
add(_block)
}
The stairs run from the bottom left to the top right of the stage. I'm uncertain if it's possible to draw more stairs say when the user is half-way up the 40 stairs to generate to generate another 40 after, effectively to work as a never ending set of stairs. Can someone give an example how to create this?
Upvotes: 0
Views: 150
Reputation: 6961
What you want to do is not to generate more stairs, but simply to move the stairs that you're no longer using to the area you're about to use. In essence, what you need is an Object Pool, such as the one shown here. Note that the one used in this example is probably a pool of data objects that are used to dynamically draw the pixels, but the concept is the same (and you might find the idea of data objects representing pixels to draw is useful in the task you have in front of you).
Upvotes: 2