Valid Move
I have problem to check if a move is valid for the player. If each tile is 32x32 and the player stands on (x,y) where x and y is the exact pixel positions on the screen. How do I check the properties (example: tile.movable == true) the tile next to the player have?
From the screen coordinates, you can get the coordinates of the tile into the tile map. If your screen is also scrolled by ScrollX and ScrollY pixels from the top-left of the tilemap, then you can get the tile coordinates like this:
That will tell you the tile that the pixel at (ScreenX, ScreenY) is in. From there, you can simply add/subtract 1 to TileX or TileY to get a neighbouring tile.
TileX = (ScreenX + ScrollX) / 32;TileY = (ScreenY + ScrollY) / 32;
That will tell you the tile that the pixel at (ScreenX, ScreenY) is in. From there, you can simply add/subtract 1 to TileX or TileY to get a neighbouring tile.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement