@Artush wrote:
Hello,
new guy here,
I need help with my code, i'm helpless right now now.i have my 2D isometric map working but, when i want to implemet mouse selection on each tile it calculates wrong
![]()
with a help from : https://gamedevelopment.tutsplus.com/tutorials/creating-isometric-worlds-a-primer-for-game-developers--gamedev-6511mouse calc Code:
public void handleMouse(GameMouse mouse, Camera camera) { mousePosition = mouse.state.Position; Point tile = mousePosition; tile.X += camera.xOffset; tile.Y += camera.yOffset; pointingAt = getTileCoordinates(tile); int temp = 0; if (pointingAt.X < 0) { temp = pointingAt.X; pointingAt.X = pointingAt.Y; pointingAt.Y = -temp; } if (pointingAt.Y < 0) { temp = pointingAt.Y; pointingAt.Y = pointingAt.X; pointingAt.X = -temp; } } public Point getTileCoordinates(Point pt){ Point tempPt = new Point(0, 0); tempPt.X = (int)Math.Floor((decimal)pt.X / (decimal)(tileHeight / 2+32)); tempPt.Y = (int)Math.Floor((decimal)pt.Y / (decimal)(tileHeight / 2+32)); return(tempPt); }
and than i just draw basic tile on top of tile that exists:
Tile selectTile = tiles.Find(selectedTile => selectedTile.positionNumber.X == (float)pointingAt.X && selectedTile.positionNumber.Y == (float)pointingAt.Y); if(selectTile != null) { int x1 = (int)selectTile.positionNumber.X * tileWidth / 2; int y1 = (int)selectTile.positionNumber.Y * tileHeight / 2; int ix1 = x1 - y1; int iy1 = (x1 + y1) / 2; Point isoCoords1 = new Point(ix1, iy1); isoCoords1.X -= camera.xOffset; isoCoords1.Y -= camera.yOffset; isoCoords1.Y += 48; Texture2D renderTexture1 = textureList.Find(texture => texture.type.Equals("basic") && texture.id == 999).getTexture2D(); selectTile.drawTile(isoCoords1, renderTexture1, tileWidth, tileHeight/2); }
when i run the game i'm getting this:
anyone have an idea how to aproach this ?
i will upload full code to GitHub
in zip on github here:
https://github.com/ArtushCz/MonoGameThank You.
Posts: 4
Participants: 2