Hello, how do I draw on a tile map, from the mouse, it uses it's own coordinate system, How do I use the mouse coordinates? The forum is black now, I like it.
How to draw on a tile map from the coordinates of the mouse?
mYusufSuleman here is some code I am using - you need to have your tile map with units marked as 0 and 1 for the tile you are using (with "1" being your "drawn" tile and "0" being blank) - here's some code I have used. You will want to play with it to get it working. Note you will need a TILE_SIZE
constant set in your header so the tilemap gets sizing correct. In this example, my TILE_SIZE is 32 pixels squared. You may or may not require the ready function which sets up the map.
const _TILE_SIZE = 32 ## math for mouse input
export(int) var _width = 32
export(int) var _height = 18
var _tempField ## holder variable
func _ready(): ## calculate cell sizes
_tempField = []
for _x in range(_width):
var _temp = []
for _y in range(_height):
_temp.append(0)
_tempField.append(_temp)
func _input(event):
if event.is_action_pressed("_click"): ## get mouse position and divide by tile size
var _pos = (get_global_mouse_position()/_TILE_SIZE).floor() ## remove decimal
set_cellv(_pos, 1-get_cellv(_pos)) ## normalize value to 1 or zero