Jump to content
  • Advertisement

Archived

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

delbogun

Valid Move

This topic is 6078 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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!