Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staggered and hex map coordinate conversion is bork #113

Open
karai17 opened this issue Jul 25, 2016 · 9 comments
Open

Staggered and hex map coordinate conversion is bork #113

karai17 opened this issue Jul 25, 2016 · 9 comments

Comments

@karai17
Copy link
Owner

karai17 commented Jul 25, 2016

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 karai17 added the bug label Jul 25, 2016
@buckle2000
Copy link
Contributor

staggered? Do you mean staggered isometric?

@karai17
Copy link
Owner Author

karai17 commented Jul 28, 2016

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
#113 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAkB_KIu_GkTWOg4tcUaoqqxYoxssNzaks5qZ_3GgaJpZM4JUL5e
.

@buckle2000
Copy link
Contributor

buckle2000 commented Aug 1, 2016

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?

@karai17
Copy link
Owner Author

karai17 commented Aug 1, 2016

What?

@jotwin
Copy link

jotwin commented Sep 15, 2016

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

@karai17
Copy link
Owner Author

karai17 commented Sep 16, 2016

Thanks, I'll have a look.

@BradFitz66
Copy link

BradFitz66 commented Sep 28, 2024

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.

@bjorn
Copy link
Contributor

bjorn commented Sep 30, 2024

@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.

@BradFitz66
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants