Discord
Login
Community
DARK THEME

How to detect on what tile you are on a map?

I need this to take damage in my game :)

You could use the collision lib by microstudio:

if mapHit(player.x, player.y, "your_map") == "spikes" then
  player.hp -= 5
end

mapHit returns the name that the tile is touching the player, 0 if no. Although now that i notice, it will check if the center of the sprite is touching the spikes, for that, you should subtract to player.y the height of the sprite, like this:

mapHit(player.x, player.y-player.height, "your_map")

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community