Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | JulioYagami |
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")
else:
print(name)
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.
Why are you making a button script anyway? Godot already has those plus other GUI nodes.
SIsilicon | 2018-12-17 13:40