Hello. I’ve used Tonypa’s tile based game-tutorial for AS3 in order to try making a game.
In the tutorial he uses a .gif with 6 different tiles. He uses actionscript to extract each of the tiles from the .gif. In the array that builds the map, he uses these numbers to define which tile to use where:
0 ( numbers below 100 are used for walls and stuff)
101
102
103
104
105
I thought that if I made my own tilesheet that had twice the height of his, I could simply write 106, 107, 108, and so on, in the array to make it put my newly added tiles on the screen. This however didn’t work very well. It seems as if it’s a bit more complicated than that. Perhaps I need to change the equations in some way? I have no idea how to change them though.
So, what should I do to make it possible to use a bigger tilesheet?
I’d be very grateful for any help.
private function getImageFromSheet (s:Number, ob:* = null):Bitmap {
var tsize:int = ts;
var sheet:BitmapData = tSheet;
if(ob != null){
tsize = ob.ts;
sheet = ob.sheet;
}
//number of columns in tilesheet
var sheetColumns:int = tSheet.width / tsize;
//position where to take graphics from
var col:int = s % sheetColumns;
var row:int = Math.floor(s / sheetColumns);
//rectangle that defines tile graphics
var rect:Rectangle = new Rectangle(col * tsize, row * tsize, tsize, tsize);
var pt:Point = new Point(0, 0);
//get the tile graphics from tilesheet
var bmp:Bitmap = new Bitmap(new BitmapData(tsize, tsize, true, 0));
bmp.bitmapData.copyPixels (sheet, rect, pt, null, null, true);
return bmp;
}