Jump to content

Random world rendering


titmael
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...