Z axis in isometric tilemap

Posted by gyhgowvi on Game Development See other posts from Game Development or by gyhgowvi
Published on 2012-07-12T01:29:58Z Indexed on 2012/09/10 15:50 UTC
Read the original article Hit count: 899

Filed under:
|
|

I'm experimenting with isometric tile maps in JavaScript and HTML5 Canvas. I'm storing tile map data in JavaScript 2D array.

// 0 - Grass
// 1 - Dirt
// ...
var mapData = [
    [0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0,
    ...
]

and draw

for(var i = 0; i < mapData.length; i++) {
    for(var j = 0; j < mapData[i].length; j++) {
        var p = iso2screen(i, j, 0); // X, Y, Z
        context.drawImage(tileArray[mapData[i][j]], p.x, p.y);
    }
}

but this function mean's all tile Z axis is equal to zero.

var p = iso2screen(i, j, 0);

Maybe anyone have idea and how to do something like mapData[0][0] Z axis equal to 3 mapData[5][5] Z axis equal to 5?

I have idea: Write function for grass, dirt and store this function to 2D array and draw and later mapData[0][0].setZ(3); But it is good idea to write functions for each tiles?

© Game Development or respective owner

Related posts about html5

Related posts about isometric