Archived

This topic is now archived and is closed to further replies.

Valid Move

This topic is 5887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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:

  
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.

Share this post


Link to post
Share on other sites