Pakz Posted June 29, 2013 Share Posted June 29, 2013 I am new with javascript and got to the point where I wanted to create a tilemap and draw that to the screen. I was not able to find anything with google so I am asking here now. How do you use javascript to store the data of a tilemap in a array? I have a blog where I put source code on and will put the tilemap example on it as soon as I get how its done. This is my blog btw : (For beginners in game programming) http://html5gameprogrammingstepbystep.blogspot.nl/ Quote Link to comment Share on other sites More sharing options...
xerver Posted June 30, 2013 Share Posted June 30, 2013 This depends heavily on a bunch of factors:How will you use the arrayWhat will be exporting the array (are you writing it by hand, exporting from an editor)?Is it a multidimensional, or a flat array?How large is it?How do you represent each tile? Quote Link to comment Share on other sites More sharing options...
Pakz Posted June 30, 2013 Author Share Posted June 30, 2013 I want to make a map in the source code. Tiles numbering from 0 to 9. It will be a multidimensional array. The size is not more then what can be put on the screen on a 320*240 map with 16*16 tiles. In java I known you can set up the tilemap in the sourcecode in a multidimensional array. something like: array[][]= { { 0,0,0,0 }, { 0,0,0,0 }, { 0,0,0,0 },}; Then you can draw using array[y][x] Quote Link to comment Share on other sites More sharing options...
xerver Posted June 30, 2013 Share Posted June 30, 2013 You can do the same in javascript: var tiles = [ [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],];for(var y = 0; y < tiles.length; ++y) { for(var x = 0; x < tiles[y].length; ++x) { drawTile(tiles[y][x]); }} Is that what you are looking for? akorukmez 1 Quote Link to comment Share on other sites More sharing options...
Pakz Posted June 30, 2013 Author Share Posted June 30, 2013 Yes that is what I was looking for. Thank you very much Quote Link to comment Share on other sites More sharing options...
sanojian Posted July 1, 2013 Share Posted July 1, 2013 If you want a bigger map, I just created a blog entry about managing large tile maps in Javascript. ttp://tinymmo.blogspot.se/2013/06/tile-maps-of-unusual-size.html Hope its useful to someone. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.