I’m iterating through a map array, adding it to tileData array with an X/Y position and tilesheet number, then calling tilesheet.drawTiles with the tileData array. A first thing I’ve noticed is it becomes a huge memory leak unless I run:
#if (cpp||php) arr.splice(0,arr.length); #else untyped arr.length = 0; #end
to clear the array before every draw. But the performance is extremely poor doing only 40fps without moving the tiles at all or doing anything else. I’ve used Love2d and have done the same thing and gotten much better performance, have I done something wrong?
I notice the drawTiles methods first argument, sheet:Tilesheet, is a sprite in my code, should I perhaps be using something else for this? Most of my code is taken from the ‘Tile based game’ tutorial: http://haxecoder.com/post.php?id=25
Heres my everyFrame function:
private function everyFrame(evt:Event):Void {
clearArray(tileData);
tilesheetCanvas.graphics.clear();
column = 0; row = 0; for (index in 0...map.length) { if (column == 40){ column = 0; row=row+1; } xpos = column*90; ypos = row*30; tileData = tileData.concat([xpos, ypos, map[index]-1]); column=column+1; } tilesheet.drawTiles(tilesheetCanvas.graphics, tileData);
}
public static function clearArray(arr:Array){
#if (cpp||php)
arr.splice(0,arr.length);
#else
untyped arr.length = 0;
#end
}
Everything draws okay, but on html5 I get only 9fps.