View Single Post
  #4  
Old 12-03-2012, 05:15 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
player.x and player.y on clientside refer to the player's position relative to the top-left of the map (not just the top-left of the current level). You can get the map width and height (in tiles) with player.gmap.width and player.gmap.height (again, clientside).

Divide the player's current x by the gmap width and you'll get a decimal representing their location on the map. If they're in the middle of the map, it'll be 0.5 for both.

When you display the player's head on a map, you can use basic math to figure out where to show it:

PHP Code:
// calculate head position on the map image
playerHeadX = ((player.player.gmap.width) * WIDTH_OF_MAP_IMAGE) - (WIDTH_OF_HEAD_IMAGE 2);
playerHeadY = ((player.player.gmap.height) * HEIGHT_OF_MAP_IMAGE) - (HEIGHT_OF_HEAD_IMAGE 2); 
Does that make sense?

There are some examples of maps in the Code Gallery you can look at as well. This one by Dusty is a few years old but replicates the default map with extra features (like being able to show a pre-rendered image). I can tell just by looking at it that some parts of it aren't done in the best way (sorry Dusty, I love you), but you can at least get an idea of the general method.
__________________
Reply With Quote