So I'm making an "unlimited" 2D Tile-Engine with procedural generation (simple noise based) in Monogame, and I'm loading/unloading Chunck by Chunck as you go along. It's working pretty well now.
Only problem I encounter when I'm positioning my character at a high value like for example int.Maxvalue / 2 (and higher), drawing tiles and every sprites from a high Position becomes all glitchy. Tiles take random sizes with a higher width and height (see pictures).
Drawing tiles :
spriteBatch.Draw(
textToDraw,
new Vector2(i * TILE_SIZE, j * TILE_SIZE),
new Rectangle(0, 0, TILE_SIZE, TILE_SIZE),
drawColor,
0,
new Vector2(0, 0),
1f,
SpriteEffects.None,
depth
);
Camera Transform :
public Matrix Transform(GraphicsDevice graphicsDevice)
{
m_Transform =
Matrix.CreateTranslation(new Vector3(-m_CameraPosition.X, -m_CameraPosition.Y, 0.0f)) *
Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Width * 0.5f , graphicsDevice.Viewport.Height * 0.5f , 0.0f)); // on redivise par 0.5 à cause du renderTarget 720x450
return m_Transform;
}
Begin spriteBatch :
matrix = this.Manager.camera.Transform(this.GraphicsDevice);
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
SamplerState.PointClamp,
null,
null,
null,
matrix
);
Drawing at position x = 1 million, y = 1 million :
Drawing at position x = 1 billion, y = 1 billion:
Red tile is a random tile I draw in another color to be able to get the size. But all the tiles are glitchy.
To isolate the problem as it didn't seem to come from my code, I tested in an Internet XNA sample I modified (From xnagpa.net "Eyes of the Dragons" samples) working with a similar Camera and tile engine. I forced the Camera position to a high value (x = 1 billion, y, 1 billion) and drawing Tiles on the screen at that position. Same problem. So my newb guess is it has to do with calculation of the Matrix, but after that it gets too complicated for me.
Anyone had the problem ? Can confirm it is a limitation of some sort. I don't think it can be fixed, but I'm trying to determine what is the "limit" of my "unlimited world".
Code is from my code base, pictures are from the example I cited and modified