translating map coords to microstudio units
if anyone has any idea how to do this please help. its for a light engine that places lights on specific map tiles ( aka: if the tiles name is "light" then it will spawn a light there )
if anyone has any idea how to do this please help. its for a light engine that places lights on specific map tiles ( aka: if the tiles name is "light" then it will spawn a light there )
Provide more details on what you want to know.
If you just want to know what tile the mouse cursor is on, for example, on the tilemap, use this example.
https://microstudio.dev/i/microstudio/collisions/
You look function mapHit( x, y, map )
what im looking for is a way to set an objects position to a tiles position example:
barry = object
x = 0
y = 0
end
barry.x = //tile's x in microstudio units or pixels
barry.y = //tiles y "'
so realy the opposite of the mouse to tile coords thing
You can map the position of the map to a screen position with this utility function:
map_range = function(x, min1, max1, min2, max2)
// map x from range (min1, max1) to (min2, max2)
return min2 + (x - min1) * (max2 - min2) / (max1 - min1)
end
So, if your tilemap has a size of (map_width, map_height) and is being drawn at (x, y) with a size of (width, height) and you want to map (tile_x, tile_y) to screen coordinates:
local tile_width = map_width / width
local screen_x = map_range(tile_x, 0, map_width, x - width/2, x + width/2) + tile_width/2
local tile_height = map_height / height
local screen_y = map_range(tile_y, map_height, 0, y - height/2, y + height/2) + tile_height/2
// spawn light at (screen_x, screen_y)
It's probably easiest to create a TileMap class containing all of the mapping code.
thank you so much!