I have a tile map engine where if you scroll all the way to the right, it crashes.
I really don't understand why as any other direction simply keeps the camera from moving past the border.
I would also like to make the world round, so moving all the way in one direction starts you on the opposite side.
Code:spriteBatch.Begin(); Vector2 firstSquare = new Vector2(Camera.Location.X / Tile.TileStepX, Camera.Location.Y / Tile.TileStepY); int firstX = (int)firstSquare.X; int firstY = (int)firstSquare.Y; Vector2 squareOffset = new Vector2(Camera.Location.X % Tile.TileStepX, Camera.Location.Y % Tile.TileStepY); int offsetX = (int)squareOffset.X; int offsetY = (int)squareOffset.Y; for (int x = 0; x < squaresDown; x++) { for (int y = 0; y < squaresAcross; y++) { int rowYOffset = 0; if ((firstX + x) % 2 == 1) rowYOffset = Tile.OddRowYOffset; foreach (int tileID in myMap.Rows[y + firstY].Columns[x + firstX].BaseTiles) { spriteBatch.Draw( Tile.TileSetTexture, new Rectangle((x * Tile.TileStepX) - offsetX + baseOffsetX, (y * Tile.TileStepY) - offsetY + rowYOffset + baseOffsetY, Tile.TileWidth, Tile.TileHeight), Tile.GetSourceRectangle(tileID), Color.White); } }


Reply With Quote
).
