I am having trouble drawing a tile-based map :(
the map however is only going to show what is VISIBLE to the player
I have a canvas
element on which i draw one layer.
On the canvas
, i use javascript to attach an image 32x32px.
The image's position is based on: $tr
$tc
as shown below:
for($tr = 0; $tr < count($mapArray)-1; $tr++) {
for($tc = 0; $tc < count($mapArray[$tr])-1; $tc++) {
if($mapArray[$tr][$tc]!== null){
echo "attachImage(" . $mapArray[$tr][$tc]. "," . $tc . "," . $tr . ",context);";
}
}
}
I don't know how I would go about making the it draw tiles from 0,0. it always starts drawing tiles from the same location on the array (ex 3,2). Maybe i'm over thinking this or im too tired... i can't find out any way :(
here's the javascript part
function attachImage(tile, x, y, canvasContext)
{
var base_image = new Image();
base_image.onload = function(){
canvasContext.drawImage(base_image, 32*(x-0),32*(y-0));
}
base_image.src = 'Images/tiles/'+(tile-1)+'.png';
}
to reiterate, i want it to start drawing from 0px,0px because i want to only display the tiles around the player.