0 votes

I have a node called GameButton that is extended by NewGameButton, OptionsButton and QuitButton

Here is the code of GameButton:

extends Node2D

var ButtonColors = {"LIGHT": Color(1, 1, 1), "MID_DARK": Color(0.5, 0.5, 0.5), "DARK": Color(0.2, 0.2, 0.2)}
var MouseIsOverButton = false

func _input(event):
    if event.is_action_pressed("mouse_left_button") && MouseIsOverButton:
        modulate = ButtonColors.DARK
    elif event.is_action_released("mouse_left_button"):
        modulate = ButtonColors.LIGHT

func _on_ButtonArea_mouse_entered():
    modulate = ButtonColors.MID_DARK
    MouseIsOverButton = true

func _on_ButtonArea_mouse_exited():
    modulate = ButtonColors.LIGHT
    MouseIsOverButton = false

And here is the code of the other nodes (and with "of the other nodes" I don't mean I use the same script file, I use differents files but the code is more or less as the follow):

extends "res://interface/GameButton.gd"

func _ready():
    $ButtonText.text = AutoLoad.LANG.NEWGAME

func _input(event):
    if event.is_action_pressed("mouse_left_button") && MouseIsOverButton:
        print(name + " pressed")
    elif event.is_action_released("mouse_left_button"):
        if self.MouseIsOverButton:
            print(name + " released")

When I click on a button, it prints %button% " is pressed", but when I release the mouse button, it prints that all the buttons were released.

in Engine by (674 points)

Why are you making a button script anyway? Godot already has those plus other GUI nodes.

Please log in or register to answer this question.

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.