Archived

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

delbogun

Valid Move

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
yeah, thats how I do it, but the problem is that this works if he walks 32 pixels each time, but I want him to walk 4 pixels, and then it doesn''t seems work...

Share this post


Link to post
Share on other sites