titmael Posted May 25, 2014 Share Posted May 25, 2014 Hi, I know different ways to generate random worlds or mazes in JS but go a question about the render of those worlds : what is the better way to load a randomly generated world in javascript (array, 2D array or why not JSON) ? Loops, tilemaps ... ? I never used that kind of world in my Phaser games, so I wonder what's the best way to do it, to be efficient when rendering and modifying (digging for example). Thx Link to comment Share on other sites More sharing options...
espadrine Posted May 26, 2014 Share Posted May 26, 2014 It is unclear what type of random world you want to generate (continuous elevation vs. tiles with ID, perlin vs. pre-generated midpoint displacement map, infinite vs. limited, can the generated world be destroyed or modified dynamically?). Is it multiplayer, is server-side processing required? If you want to render the world fast, you have two possibilities: generate rectangles of the world server-side, and feed the client images dynamically (those images can contain any type of data, including tile IDs; you can have a sprite image on the side), or use a PRNG such as Mersenne Twister and hook a JS world generator onto it, which guarantees you get the same world, given the same seed (in that case, you may want to cache the generated world if necessary; free advice: cache it in canvas elements, which get drawn fast). Of course, if your generated world contains a very small amount of information, JSON is just fine. Link to comment Share on other sites More sharing options...
titmael Posted May 26, 2014 Author Share Posted May 26, 2014 Thanks. My question wasn't precise enough I generate a random maze that can be more thant 200*200. I don't know if it's a giant maze for the render. And my tiles are from a png sprite. Link to comment Share on other sites More sharing options...
Recommended Posts