0 votes

Hi all,


If you look at that GIF you'll see the problem.

I can guarantee the cards coming out of the left pile and onto the right have the correct Z_Index. You can see the newest cards raise to the top and sit on top of the ones on the bottom.

Why then is the mouse not selecting the card on the top? I'm a little stumped.

Any advice greatly appreciated.

Thank you.

in Engine by (824 points)

1 Answer

0 votes

in my game i can have a few items covering each other. and my code always select the top item. take a look and maybe you can make it work for you aswell.

func _input_event(viewport, event, shape_idx):
if event is InputEventMouseButton \
and event.button_index == BUTTON_LEFT \
and event.is_pressed():
    if Global.mouse_selection and selected:
        selected = false
        Global.mouse_selection = false
        Global.object_selected = null
    elif Global.mouse_selection == false and selected == false:
        selected = true
        Global.mouse_selection = true
        Global.object_selected = self
    elif Global.mouse_selection == true and selected == false:
        selected = true
        Global.object_selected.selected = false
        Global.object_selected = self

i have a global script singleton that holds those two variables "objectselected and mouseselection"

EDIT: and by the way, my item scene contains area2d, collision shape and a sprite

by (157 points)
edited by
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 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 webmaster@godotengine.org with your username.