Define fixed coordinate starting point on an “infinite” map

How do you determine world coordinates for a 2d top-down “infinite” terrain map? Screen coordinates that I use to render everything are relative the viewable frame, and once I add a save-game feature the players starting point should be where they were when they last quit…

So I have one relative-based coord system, a player starting point that will likely not always be the same - how do I come up with a system of “fixed” coordinates that can be used to describe locations on the map?

I’ve asked this in multiple places and so far, no one’s had any ideas.

Example: Even though it’s 3d, Minecraft generates world coordinates that are some how tied to a fix point of the map. They’re not based on the player location and obviously don’t depend on translating the screen coordinates.

Thanks!

Hmmm… How to explain this.

Make a normal world, that is NOT centred on the player or anything, fixed coordinates.

When rendering use Graphics2D.translate() or GL11.glTranslatef() to translate the player to the centre.

Can you clarify what “make a normal world” and “fixed coordinates” mean? Right now, I’m generating terrain for the “viewable area” when the game starts and then new terrain as the player moves.

Then don’t generate for the screen space.

Generate from 0,0 to x,y

Ok, help me walk through the thought process:

  • New game starts. I generate terrain for a fix size and decide that the first tile will become known as “0,0”
  • I use a method to properly convert world coords to screen coords, so that portion of the map can be seen
  • Player moves to 1,000x1,000, saves the game. During save, I write to a file their coords - 1000x1000
  • Loads the game the next day. I load the save game file, read the world coords
  • Then again I covert those world coords to screen coords, and place the player back.

That sounds like it’ll work, is that what you’re recommending?

No converting to screen coords is required.

Just use a translate function to centre the world on the player when rendering.

I’ve been coding this game for a week solid, this is hurting my brain now - lol.

I think a big problem for me is that all of my code is based on the movement around the viewable area - so I’m trying to think about how best to integrate this.

The only way for me to know what coordinate the player has moved to is to track the distance from “spawn” they travel, right?

No.

Ignore the rendering for now.
Just think about the logic side of things.

Everything in the world should have an absolute position.

Just think about it as if the screen is not centred on the player. (and imagine you have an really big screen that can view any part of the world)

Hi viveleroi,

I think you are getting a bit caught up on the world vs. screen coordinates thing. From your initial post, it sounds like you are working with screen coordinates, and trying to convert them back into world coordinates.

Work the other way around. Do everything in world coordinates; terrain gen, player position etc. When it comes to rendering the world, as Heroes has pointed out, just translate everything to its screen position. This will essentially be WorldCoords - ViewCoords, where ‘ViewCoords’ is the position of your view/screen/camera/whatever you want to call it. (The view may be centred on the player, or might be scrollable etc.).

The ‘world’ is one thing; the ‘view’ is a different beast. The world should be able to exist and function independently of the view. As the name suggest, the view is just a ‘viewport’ into the world; it shouldn’t change what happens in the world, nor the position of objects within the world. The view itself will likely have a position in world coordinates.

nerb.