Hey all
I’m starting work on a new game that has a lot of shapes dynamically generated on the stage. They’re all the same shape, just different sizes. I figured the best way to do this would be an array of movieclips, but then I remembered hearing that things run much better when you clone things out of Bitmap Data. Finding good examples of either solution has been difficult, so I thought I’d try my own.
Here’s what I have so far:
package {
import flash.display.MovieClip;
import flash.display.Shape;
import flash.display.Bitmap;
import flash.display.BitmapData;
public class Magnetron extends MovieClip {
private var circleSize:Number;
private var maxSize:Number;
private var numPullers:Number;
private var numPushers:Number;
public function Magnetron():void {
createPullers();
}
private function createPullers():void {
numPullers = 10;
maxSize = 50;
for(var i:Number = 0; i < numPullers; i++){
circleSize = Math.round(Math.random()*maxSize);
if(circleSize < 10){
circleSize = 10;
}
var circle:MovieClip = new MovieClip();
circle.name = "circle"+i;
circle.graphics.beginFill(0x000000);
circle.graphics.drawCircle(circleSize,circleSize,circleSize);
circle.graphics.endFill();
var pullerBMData:BitmapData = new BitmapData(circleSize*2, circleSize*2, true, 0xFFFFFF);
pullerBMData.draw(circle);
var puller:Bitmap = new Bitmap(pullerBMData);
puller.x = Math.round(Math.random()*stage.stageWidth);
puller.y = Math.round(Math.random()*stage.stageHeight);
stage.addChild(puller);
}
}
//=====================================================================
}
}
Well, it works. It puts a bunch of black circles on the stage in random spots, and there’s transparency around the circles. However, here are my concerns:
[LIST=1]
[]Is this the right way to copy things out of BitmapData?
[]If not, what is the right way? Or, what’s a better way?
[]If so, will this actually save on loading/processing?
[]How will this method affect hit detection? And what’s the best form of hit detection to use here?
[*]Is it still a good idea to load the different shapes into an array to keep track of them? Or is there a better way to keep track?
[/LIST]
A hundred questions, and I’ve just started. I thank anyone who can offer some insight into this!