Simple-Tiled-Implementation icon indicating copy to clipboard operation
Simple-Tiled-Implementation copied to clipboard

Staggered and hex map coordinate conversion is bork

Open karai17 opened this issue 9 years ago • 9 comments

Using the convertTileToPixel and convertPixelToTile methods, getting the pixel location or the tile location of a point is very important. This can be used for, say, clicking your map with your mouse to have a player path to that location, or some such thing. This feature works perfectly fine for both ortho and iso maps. However, hex and staggered maps are totally broken in this regard, and I cannot seem to figure out the math to fix them.

Like ortho/iso, I'd like to be able to retrieve non-whole numbers for tiles so you can know the relative location within a tile that the user clicked on. Users can then floor that number if they want the whole number representation of the tile.

karai17 avatar Jul 25 '16 14:07 karai17

staggered? Do you mean staggered isometric?

buckle2000 avatar Jul 28 '16 00:07 buckle2000

Yes.

On Jul 27, 2016 9:54 PM, "buckle2000" [email protected] wrote:

staggered? Do you mean staggered isometric?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/karai17/Simple-Tiled-Implementation/issues/113#issuecomment-235766869, or mute the thread https://github.com/notifications/unsubscribe-auth/AAkB_KIu_GkTWOg4tcUaoqqxYoxssNzaks5qZ_3GgaJpZM4JUL5e .

karai17 avatar Jul 28 '16 01:07 karai17

In my opinion, using 2 non-whole numbers can never represent a hex tile correctly. And is the pixel origin (0,0) of staggered and hex map useful to the user?

buckle2000 avatar Aug 01 '16 06:08 buckle2000

What?

karai17 avatar Aug 01 '16 11:08 karai17

Here is a good reference for hexagons http://www.redblobgames.com/grids/hexagons/implementation.html

jotwin avatar Sep 15 '16 03:09 jotwin

Thanks, I'll have a look.

karai17 avatar Sep 16 '16 07:09 karai17

I know this is an old issue, but it appears that staggered coordinates are still broken.

Unless I'm using convertPixelToTile wrong, that is. I'm getting mouse coordinates via love.mouse.getPosition() and then using those as the arguments for convertPixelToTile and then attempting to delete (setLayerTile to GID 0) using the coordinates it gives me, but it doesn't seem to work.

Here's what I'm seeing(white circle represents my cursor): STIBug

Map is a staggered isometric type map.

BradFitz66 avatar Sep 28 '24 14:09 BradFitz66

@BradFitz66 Did you have a look at whether https://github.com/karai17/Simple-Tiled-Implementation/pull/262/commits/c732a6c065d4492809feb5a470d334d7cce6856e fixes it? If so, you could open a new PR with that change (or your own version) since the one #262 came from has been deleted.

bjorn avatar Sep 30 '24 12:09 bjorn

@BradFitz66 Did you have a look at whether c732a6c fixes it? If so, you could open a new PR with that change (or your own version) since the one #262 came from has been deleted.

@bjorn Unfortunately, it does not seem to work either.

Just incase I'm doing this incorrectly, my code is below:

    local mx,my = love.mouse.getPosition()
    tx,ty = map:convertPixelToTile(mx,my)
    tx=math.floor(tx)
    ty=math.floor(ty)

    if(love.mouse.isDown(1)) then
        map:setLayerTile(1,tx,ty,0)
    end

Here's the result: whyy

BradFitz66 avatar Sep 30 '24 21:09 BradFitz66