Jump to content

  • Log In with Google      Sign In   
  • Create Account


Tile Maps and Snapping player coordinates


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 BytePtr   Members   -  Reputation: 106

Like
0Likes
Like

Posted 24 October 2011 - 05:30 PM

Hi.

For example i create simple tile map and add player to it.
When i press left, right, up or down key i will increase or decrease X and Y pos, like this for example (C++):

xpos += 1;
ypos += 1;

Map is define by simple numbers 0 and 1 etc.
0 is grass
1 is rock etc...

Depending on number i draw specific tile. Now let's say my tiles are all 64x64 pixels.
I would like to get "full" coordinates of player.
I mean, let's say map width is 256 and height also 256.
So if player is at X: 2 Y: 2 (at which the map tile ID is 1 for ex) then i must get his coordinates also like they are: X 2 and Y 2.
If he moves away from tile ID 1 then coordinate must also increase by one. Not by 1.42343 or something...

I don't know how to explain it better. It just must increase coordinate value only if he moves away from one tile to another.
If player is in one tile and moving within that tile, then coordinate values should stay same.

But i don't know the math behind it. Should i use % operator to do what i need or something else?


Thanks for any help.

Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 15099

Like
1Likes
Like

Posted 24 October 2011 - 05:44 PM

int MapCoordinateX = RealCoordinateX / TileWidth;
int MapCoordinateY = RealCoordinateY / TileHeight;

#3 BytePtr   Members   -  Reputation: 106

Like
0Likes
Like

Posted 27 October 2011 - 02:34 PM

Seems to work fine enough.

Thank you.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS