Quick answer: tilemap_get returns the tile data with rotation and flip bits packed in. Use tile_get_index to extract just the index for comparisons. For solid checks, the tile’s source sprite must have a collision mask configured; otherwise tile_meeting always returns false.
Here is how to fix GameMaker GMS2 tilemap collision checks that report wrong values. Your character walks through walls because tile_meeting says no collision. Or your wall-detection script stops working when a tile is rotated. The cause is the bit-packed tile data format and the requirement that source sprites have collision masks.
The Symptom
tile_meeting returns false on tiles you can see. Or comparing tilemap_get(layer, cx, cy) == TILE_GROUND fails when the tile in question is flipped or rotated, because the data includes those flags.
What Causes This
Raw tile data includes flip/rotation bits. tilemap_get returns a 32-bit value where the index is the lower bits and rotation/flip are upper bits. Direct comparison fails when those upper bits are non-zero.
Sprite has no collision mask. tile_meeting checks the source sprite’s collision shape. If the sprite’s mask is not configured, the function returns false even on tiles with visible art.
Layer ID wrong. tilemap_get_at_pixel needs a specific tilemap layer ID, not a layer name. Use layer_tilemap_get_id(layer_get_id("Walls")).
World vs screen coordinates. Functions like tilemap_get_at_pixel expect world coordinates, not view-relative.
The Fix
Step 1: Strip flag bits before comparing.
var _data = tilemap_get_at_pixel(layer_walls, x, y);
var _idx = tile_get_index(_data);
if (_idx == TILE_GROUND) {
// solid floor
}
tile_get_index extracts the lower bits cleanly. Use this for any comparison.
Step 2: Configure source sprite collision mask. Open the sprite that the tilemap uses (often called something like spr_tileset_walls). Set Collision Kind to Rectangle or Precise. tile_meeting now uses this mask.
Step 3: Cache the layer ID.
// Create event of oController
layer_walls = layer_tilemap_get_id(layer_get_id("Walls"));
Cache once. Looking up by name every frame is wasteful.
Step 4: Use world coordinates.
// In a player object's Step event - x and y are world coordinates
if (tile_meeting(layer_walls, x, y + 2)) {
// player is on solid ground 2px below
}
If you need to convert from a mouse or device position, use device_mouse_x_to_gui conversions or just mouse_x which is already world.
Step 5: Read flag bits if you need them.
var _data = tilemap_get_at_pixel(layer_walls, x, y);
var _idx = tile_get_index(_data);
var _rot = tile_get_rotate(_data);
var _flipx = tile_get_flip(_data);
var _flipy = tile_get_mirror(_data);
Useful for tile-aware behaviors like reading slope direction from the rotation flag.
Common Patterns
Floor check: if (tile_meeting(layer_walls, x, y + 1)) just below the player.
Wall check: if (tile_meeting(layer_walls, x + sign(hspeed), y)) in front.
Hazard tile: if (tile_get_index(tilemap_get_at_pixel(layer_hazard, x, y)) == TILE_LAVA).
Performance Note
tile_meeting is fast (sprite collision check); tilemap_get_at_pixel is also cheap. Both can be called multiple times per Step without measurable impact for typical hundreds of objects. For thousands, consider precomputing solid grid arrays at level start.
“Tile data is packed. Strip flags before comparing. Source sprites need masks. World coordinates only.”
Related Issues
For surface lifecycle, see Surface Lost After Resize. For shader uniforms, see Shader Uniform Per Frame.
tile_get_index strips flags. Sprite mask enables tile_meeting. World x/y. Solid checks work.