Friday 25 April 2014

The Wanderer - 2D Open World (prototype)

Three days ago I made a post about my plans on how to convert my 2D Wanderer game into an open world Wanderer. I'm writing here now to report that my plans have been successful, although there's still a few bugs left to iron out and I also need to optimise my functions so that there's less of a framerate drop when loading chunks.

I'm not convinced this is the best way to do it, but it's a first attempt and at least it works.

Anyway, here's how I did it. Of a much bigger world I establish a viewpoint into this world that's 1760x1760 pixels large. This is then divided into 9 sections arranged into a 3x3 grid:

123
456
789

The player is on chunk 5. If he moves onto one of the other chunks, then the chunks need to be rearranged. For example, if he's standing on 5 and moves to 6 then the following needs to happen:

Chunks 2 5 8 need to be moved back to chunks 1 4 7.
Chunks 3 6 9 need to be moved back to chunks 2 5 8.
Chunks 3 6 9 then need to be reloaded.

This creates an effect where if the player moves off chunk 5 then the world is rearranged so that he's again on chunk 5. Just like in this picture:


Here's some screenshots of my Wanderer in action. In this picture, he's just spawned at tile 64,64.


Now I turn the grid on, and the tile coordinates on, and walk east until I reach chunk 6 (which forces a shuffling and loading of chunks):


Then I walk against east, until a new chunk is loaded.


Here's another shot at a different location with the chunks coloured.


Anyway, it's an ok first attempt at getting an open world to work, but I've got problems with framerate and glitches to overcome before I label it as a success.

2 comments:

  1. Interesting, thanks of this post. Got my head around problems that I had with overworld games such as the location being visible only.
    Though, wouldn't the scrolling you use ..be not smooth but rigid?

    ReplyDelete
  2. The camera always follows the player (I coded that) so it's not like jerky chunk movements being seen everywhere. When the chunks get changed the camera is still directly over the player - no slidey earth type stuff noticable. However the minimap does jerk. It looks like the red circle moves almost to the edge and then, suddenly, it's again in the middle.

    I split the loading up into a few threads, and now there's just a tiny pause of maybe 0.2 of a second or something. That's the only clue you get when chunks have been changed (aside from being able to keep on walking in the direction you want).

    ReplyDelete