Reputation: 3050
var square:Sprite = new Sprite();
var tileWidth:int = 32;
var tileHeight:int = 32;
var row:int = 0;
for (var i:int=0;i<5;i++) {
if (i > 0)
{
row = 32 * i;
}
square.graphics.beginFill(0x000000);
square.graphics.drawRect(row,0,32,32);
square.graphics.endFill();
addChild(square);
}
This is my code so far, is square.graphics the way to go? How do I draw a tile that is a picture? Do I need to hold the graphics in some sort of array to do checking like collision?
Upvotes: 1
Views: 420
Reputation: 1713
If you are going to desire any performance out of this, you need to look at things like blitting - or copying pixel data from a source image to single display object in this case. So you make a crazy image with all your tiles on it. Then your blit engine copies specific boxes of the image representing that tile to a specific place in the larger display object.
Google - as3 blitting - or check out http://freelanceflashgames.com/news/2010/02/08/bold-pixel-engine-an-as3-framework-for-games/
Upvotes: 1