This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'd like to use the built in signals but I'm creating the node that I want to use with the TextureRect.new() in code.

I know i can make a custom signal. That's not what I want to do though.
Is there a way to use the built in signals on mouse entered and exited through just code?
I guess I need to know how to turn the signal on and how to write a function for the signal.

in Engine by (60 points)

2 Answers

0 votes

Check the documentation:

var new_rect = TextureRect.new()
new_rect.texture = load("<ImagePath>")
new_rect.connect("mouse_entered", self, "on_TextureRect_entered")
new_rect.connect("mouse_exited", self, "on_TextureRect_exited")
add_child(new_rect)

func on_TextureRect_entered():
    print("TextureRect entered!")

func on_TextureRect_exited():
    print("TextureRect exited!")
by (10,634 points)
+1 vote

Sure, you can do that in code. Here's an example, though you'll likely need to season it to taste based on your code strucuture.

func _ready():
    $TextureRect.connect("mouse_entered", self, "_on_mouse_entered")
    $TextureRect.connect("mouse_exited", self, "_on_mouse_exited")

func _on_mouse_entered():
    print("Mouse entered")

func _on_mouse_exited():
    print("Mouse exited")

Here, I'm referencing a TextureRect instance that I created in the editor, but it doesn't matter. Just replace my $TextureRect with your code-created reference.

by (22,704 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.