1
\$\begingroup\$

I am rendering a diamond isometric map created in Tiled using Monogame.Extended.Tiled package.

Here is where I'm trying to spawn a player with an object at coordinates 224,224 on my map

Spawn

Here is where it actually spawns within the game world. Actual game

I have some debug info at the top of the screenshot. 0, 0 in the gameworld is where the first tile is in the middle of the screen.

I understand how to get the correct coordinates when it is a staggered map. I know for a diamond it involves something with the halving the screen size and height but I'm personally stuck and have tried searching for this answer somewhere.

I just want to be able to convert the coordinates Tiled puts out, into the world space. If it comes to it, I will just use my own map renderer and go back to staggered but I would prefer not to.

My tiles are 64px wide, 32px tall

As usual, any help is appreciated and will provide any extra information.


Edit

Here are updated screenshots with regards to the comment. I hope they're correct.

Below are tiles with the coordinates + origin. These are objects in Tiled where I wish to place something.

enter image description here

Here is where they are actually rendered.

enter image description here

I am confused as to why the origin is offset on the Y coordinate like that but this is rendered using Monogame.Extended.

\$\endgroup\$
0
0
\$\begingroup\$

It looks like you want something like...

pixelY = tileHeight * (tileX + tileY)/2 + tileHeight;
pixelX = tileWidth  * (tileX - tileY)/2;
\$\endgroup\$
7
  • \$\begingroup\$ Looks like that might solve it. I will give it try when I get a chance soon. I was getting very confused because MonoGame.Extended has a worldToScreen method but it wasn't lining anything up correct. Thanks in advance and I will accept this once I check it works. \$\endgroup\$
    – Emobe
    Sep 5 at 12:57
  • \$\begingroup\$ I've never used MonoGame.Extended, but I wonder whether the "world" it refers to there is something like a physics world, rather than the tilemap. \$\endgroup\$
    – DMGregory
    Sep 5 at 12:58
  • \$\begingroup\$ Yeah it just needed this equation ontop of that worldToScreen method. Thanks for saving me from this headache. \$\endgroup\$
    – Emobe
    Sep 5 at 13:02
  • \$\begingroup\$ Want to post your own answer showing how to incorporate this into your code alongside worldToScreen? Maybe call it a function tileToWorld 😉 That way you can accept your own answer and keep your bounty — I really don't need it. \$\endgroup\$
    – DMGregory
    Sep 5 at 13:04
  • \$\begingroup\$ Yeah I probably will make it an answer cheers. Just curious though, I'm doing some debugging and I'm wondering does any of the 32 represent the pixel width or height? My tiles are 64*32 so I was wondering if it's supposed to represent any of them \$\endgroup\$
    – Emobe
    Sep 5 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.