Hey Codeproject,
I'm creating an isometric game but there is a problem with the mouse translations. I use a Matrix-based 2D camera for this, and this does not have any issues. I already know how to translate my "screen" position into a "world" position, but since I'm rendering in an isometric view I do not know how to make the "world" position get transformed into the "isometric position."
public void Draw(SpriteBatch SpriteBatch, Vector3 Position)
{
if (WorldFarmer.TileSet != null)
{
SpriteBatch.Draw(WorldFarmer.TileSet, new Rectangle(
(int)(Position.X - Position.Y) * (int)Size.X / 2,
(int)(Position.X + Position.Y) * (int)Size.Y / 4 + (int)(Position.Z * Size.Z / 2),
(int)Size.X,
(int)Size.Y)
, SourceRectangle, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 1f);
}
}
This is how I render my tiles - no issues here either.
Can anyone please help me? I can not seem to get this right no matter what I try.
What I have tried:
var Pos = Camera.Position / new Vector2(Tile.Size.X / 2, Tile.Size.Y / 4);
Tile.Draw(SpriteBatch, new Vector3(Pos, 10), Color.Red);
That's so far my attempt, but my red block seems to either fly away from the camera, or just move way too slow. I'm obviously missing some obvious math. :/