Click here to Skip to main content
15,667,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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."

  /// <summary>
       /// Draws the tile.
       /// </summary>
       /// <param name="SpriteBatch">The spritebatch to draw the tile with.</param>
       public void Draw(SpriteBatch SpriteBatch, Vector3 Position)
// Position = not pixel position, but grid position. Size = tile size (64, 64), and source rectangle is also w64, h64
           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),
               , 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. :/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900