If you're performing collision detection against a tilemap whose tiles are very simple (as in, the tiles aren't complicated to the point where a tile can be solid on one half, and empty on the other half, tiles aren't round or have funny-shaped edges, things like that), then you can take advantage of this fact, and the fact that every tile is the same size.
Let's pretend the player is 12x12, and the tiles of the tilemap are 8x8. It'll look something like this:
Code:
╔══════╗
║ ║
║ ║ ┌──────────┐
╚══════╝ │ │
╔══════╗ │ PLAYER │
║ ║ │ │
║ ║ │ │
╚══════╝ └──────────┘
╔══════╗╔══════╗╔══════╗╔══════╗
║ ║║ ║║ ║║ ║
║ ║║ ║║ ║║ ║
╚══════╝╚══════╝╚══════╝╚══════╝
To check the bottom edge of the player against the tilemap, first, look at the bottom left corner of the player, down one extra pixel, and sample the properties of the tile at this point:
Code:
╔══════╗
║ ║
║ ║ ┌──────────┐
╚══════╝ │ │
╔══════╗ │ PLAYER │
║ ║ │ │
║ ║ │ │
╚══════╝ └──────────┘
╔══════╗╔═══█══╗╔══════╗╔══════╗
║ ║║ ║║ ║║ ║
║ ║║ ║║ ║║ ║
╚══════╝╚══════╝╚══════╝╚══════╝
Next, move your point to the right by the width of a tile (in this case, 8 pixels), but only if it doesn't exceed the width of the player. Because you're moving by the width of a tile, you are guaranteed to be looking at the next tile over:
Code:
╔══════╗
║ ║
║ ║ ┌──────────┐
╚══════╝ │ │
╔══════╗ │ PLAYER │
║ ║ │ │
║ ║ │ │
╚══════╝ └──────────┘
╔══════╗╔═══░══╗╔═══█══╗╔══════╗
║ ║║ ║║ ║║ ║
║ ║║ ║║ ║║ ║
╚══════╝╚══════╝╚══════╝╚══════╝
Moving the point by the width of a tile again will exceed the width of the player. So instead, check the bottom right corner of the player, down one extra pixel, and sample the properties of the tile at this point:
Code:
╔══════╗
║ ║
║ ║ ┌──────────┐
╚══════╝ │ │
╔══════╗ │ PLAYER │
║ ║ │ │
║ ║ │ │
╚══════╝ └──────────┘
╔══════╗╔═══░══╗╔═══░══█╔══════╗
║ ║║ ║║ ║║ ║
║ ║║ ║║ ║║ ║
╚══════╝╚══════╝╚══════╝╚══════╝
If any of those tiles were solid, then the player doesn't fall. If zero of those tiles were solid, then the player falls.
Checking the other edges of the player work in a similar manner: To check the left edge of the player, start at the top left corner of the player (pushed out one pixel to the left), and move down in "tile_height" increments, sampling each pixel until you get to or move past the bottom left corner (pushed out one pixel to the left), at which point you check the bottom left corner itself. If all of the tiles at those pixels were solid, then the player can't pass through. If none of them were solid, then they player can pass through.