ID:2194252
 
(See the best response by Avainer1.)
Not sure if I can post math questions here....
I'm trying to place player pin images on a png I have laid down somewhere in the interior. Basically the world is 1000x1000. The png is a map of the world (544x544). I want to find the offsets of the pin so that it corresponds to the players location on the actual world map.
Best response
I'm not sure if this will work, but I'll post the logic.
Your map is 1000x1000, that's in tiles. Assuming your tiles are 32x32, then you have 32k x 32k PIXELS. Now, you want to convert your location from tiles to pixels, by just multiplying by 32.
Ie, you are on (2,2) That's (64,64) in terms of pixels.

Now, you want to pin this (64,64) onto your png, and to do that, we use ratios. Png's size is already in pixels, which is 544x544. So, what we're going to do is multiply the (64,64) by 544/32000. That's 0.017. But, since we're working with integers, we can use floor() or ceil() whichever you prefer to get it there.


Another example: loc(500,540) in pixels is (16k,17.28k)

Multiply by 544/32000 that's (272, 294) on your png.
Note that you can also simplify a bit further due to the massive size difference. For instance, you could do:

pin_x = round(player.x*0.544)
pin_y = round(player.y*0.544)
Awesome, great help. Thanks a ton guys