0 votes

I solved this problem, I forgot that the input does not work on top of the gui

i am trying to connect these signals but they are not being called

this script is the parent script of another script that connected to the node

extends Area2D

var is_drag := false
var mouse_entered := false

func _ready() -> void:
    utils.assert(connect('mouse_entered', self, '_on_mouse_entered') == OK)
    utils.assert(connect('mouse_exited', self, '_on_mouse_exited') == OK)

func _on_mouse_entered() -> void:
    mouse_entered = true

func _on_mouse_exited() -> void:
    mouse_entered = false

func _unhandled_input(event):
    if event is InputEventMouseButton and mouse_entered:

        if event.is_pressed():
            is_drag = true
            is_drag = false

func _physic_process(_delta: float) -> void:
    if is_drag:
        position = get_global_mouse_position()

child script:

extends 'res://parent_scripts/equipment.gd'

var physical_defence := [0, 1]
var magic_defence := [0, 1]

func init(init_name, init_min_physical_defence, init_max_physical_defence, init_min_magic_defence, init_max_magic_defence) -> void:
    name = init_name
    physical_defence[0] = init_min_physical_defence
    physical_defence[1] = init_max_physical_defence
    magic_defence[0] = init_min_magic_defence
    magic_defence[1] = init_max_magic_defence

    $Sprite.set_texture(load('res://sprites/%s.png' % name))
    $CollisionShape2D.shape.set_radius($Sprite.texture.get_width() / 2)

func get_passing_damage(input_physical_damage: int, input_magic_damage: int) -> Array:
    var physical_passing_damage := input_physical_damage -    global.get_random_int(physical_defence[0], physical_defence[1]) as int
    if physical_passing_damage < 0:
        physical_passing_damage = 0
    var magic_passing_damage := input_magic_damage -     global.get_random_int(magic_defence[0], magic_defence[1]) as int
    if magic_passing_damage < 0:
        magic_passing_damage = 0
    return [physical_passing_damage, magic_passing_damage]

func _physics_process(delta):

through this script, the script connects to the node

extends Panel

var item

func _ready() -> void:
    var child := load("res://objects/item.tscn").instance() as Object
    child.init('shield', 2, 5, 0, 0)
    child.position = Vector2(50, 50)
Godot version 3.2.3.stable.official
in Engine by (141 points)
edited by

1 Answer

0 votes

Juste to clear the confusion for others: by default, a control node will capture the mouse. You can alter this behavior by setting the mouse_filter option to MOUSE_FILTER_IGNORE or MOUSE_FILTER_PASS. You can set it in the editor, or by code.

From the docs: "Sets mousefilter to MOUSEFILTER_IGNORE to tell a Control node to ignore mouse or touch events. You'll need it if you place an icon on top of a button". https://docs.godotengine.org/fr/stable/classes/class_control.html?highlight=Control#enum-control-mousefilter

by (617 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 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.