0 votes

what i want to do is, when mouse at top of cell=0 , it will change to cell=4. and when mouse not at top that cell, it will return to cell = 0

how to check if my mouse leave my cell?
how to change back cell=4 to cell= 0 wihout mouse at top cell 4?
people tell me use get_cellv(), but how to check all cell that change to cell=0, if one cell change, i still can use vecktor(something,something) to change it id back. but if more than 100 cell, how to check all?

func _unhandled_input(event: InputEvent) -> void:
    var mouse_pos = get_viewport().get_mouse_position()
    var tile_pos = world_to_map(mouse_pos)
    var tile_cell_at_mouse_pos = get_cellv(tile_pos)
    var current_cell :bool = true

    if event is InputEventMouseMotion and tile_cell_at_mouse_pos != INVALID_CELL and tile_cell_at_mouse_pos == 0 : #hover tile
        if current_cell == true: 
            set_cellv(tile_pos,4)
            current_cell = false

    else:

        ?????????????
        current_cell = true
        print(tile_pos

gray cell =4. and grass cell=0
enter image description here
this what i meant when i say cell =0 or cell 4. their id.
enter image description here

in Engine by (419 points)
edited by

1 Answer

0 votes
var last_cell = Vector2()
    if event is InputEventMouseMotion and tile_cell_at_mouse_pos  != INVALID_CELL and tile_cell_at_mouse_pos == 0 : 
        var mouse_cell = world_to_map( event.position )

        if mouse_cell != last_cell:   ############# hover, var last_call at top/ouside funtion
            set_cellv( last_cell, 0 )
            set_cellv( mouse_cell, 4 )
            last_cell = mouse_cell
            print("last_cell",last_cell)
            print("mouse_cell",mouse_cell)
by (419 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.