Binary data management in JavaScript!
As I promised in a previous post, I made a library that facilitates the use of typed arrays in JavaScript. The library is here. This is great for tile based games in JavaScript because it permits to make easy to use grids that use less memory. You can have Grids of 8bit, 16bit, or 32bit signed or unsigned integers. It also has a compatibility mode that makes my library work on browsers that don’t yet support typed arrays by using a image data pixel array instead( but it only works on 8bit unsigned grids). I was going to post a demo but my free provider is down for some reason so..You can use it like this:
var map = binaryData.Grid(100,15,8,false) ;//make a 100×15 8bit unsigned grid initialised to 0.
map.set(2,2, 25); // set the (2,2) to 25
alert(map.get(2,2)); //should get the (2,2) and alert 25
map.paste(3,3,
[[0,5,5,0,0,5,5,0],
[5,5,5,5,5,5,5,5],
[5,5,5,5,5,5,5,5],
[0,5,5,5,5,5,5,5],
[0,0,5,5,5,5,5,0],
[0,0,0,5,5,5,0,0],
[0,0,0,0,5,0,0,0],
[0,0,0,0,0,0,0,0]]); // not really obvious here, but pastes a heart mde out of 5s on the grid at position (3,3).
map.forEach( function(value,x,y) {/*put your drawing routines here*/}); // forEach can also be executed only on a defined area of cells like this:
map.forEach(function(value,x,y) {/*blabla*/},2,2,10,10)// executes the function on the 10×10 cells that start at (2,2)
//by drawing only the cells on the screen, you can greatly optimise side-scrollers.
this is enough. Once atspace.com will be back up, I will post a small demo, and maybe a documentation. And maybe move my thing to bitbucket or github or something.. herpderp.. but that will be tomorow. night everyone..fgHRWf3x zzzzz