![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Izaro |
Hello!
As stated in the title, I’m trying to make it so that the tiles change when the mouse hovers over them while the left mouse button is clicked. At first, I thought that I’m close to the solution with this code:
const BLACK = 0
const WHITE = 2
const RING = 3
const GRAY = 4
const GREEN = 5
const RING_GREEN = 6
const BLACK_GREEN = 7
func _unhandled_input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
var clicked_cell = world_to_map(event.position)
var color_check = self.get_cellv(clicked_cell)
match color_check:
WHITE:
self.set_cellv(clicked_cell, GREEN)
BLACK:
self.set_cellv(clicked_cell, BLACK_GREEN)
RING:
self.set_cellv(clicked_cell, RING_GREEN)
GREEN:
self.set_cellv(clicked_cell, WHITE)
BLACK_GREEN:
self.set_cellv(clicked_cell, BLACK)
RING_GREEN:
self.set_cellv(clicked_cell, RING)
But while this code works great for one click, it doesn’t to anything when the left mouse button is already pressed. Because of that, I then proceeded to try to get a similar function to work in the process function using
if Input.is_mouse_button_pressed(BUTTON_LEFT):
, but I always failed to get the “world_to_map” function to work with that.
I don’t know how to achieve my goal anymore at this point and hope that somebody here can help me.^^’