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.
+1 vote

Hello,

using TextureRect over Sprite2D is that bad ? i do it because Sprite2D dont have any signal about mouse event.

in order to detect mouse click over a Sprite2D we have to:

1- add an area2d
2- add a 2d shape
3- resize the shape
4- connect area2d signal

in order to detect mouse click over a TextureRect we have to:

1- connect gui_input signal

is there an easy way to detect mouse event on a sprite2D that i dont know ?

Using TextureRect instead Sprite2D will probably impact my game later ?

What the reason of this Sprite2D node since we have TextureRect node too?

They seem to be the same for me, except Sprite2D cant interact with mouse and TextureRect is designed for UI

so should i use TextureRect when i want a "sprite" that can interact with mouse easily, and use Sprite2D for the rest that dont need to react to mouse ?

in Engine by (25 points)

2 Answers

0 votes

Sprite serves visual purpose only. Only Area can detect mouseenter. Area has advantage over texturerect, as it can have multiple complicated shapes, not just a rectangle. If You only need rectangular shape, You can use texturerect. It is even more optimal sollution this way. However You need to be aware of gui_input handicaps. Guiinput can be consumed by other control nodes that overlay your texture rect. This is why they are mainly used for focusing menus and tooltips - to make sure only one UI element is focused and clickable at a time. So make sure nothing interrupts your mouse detection for texture rect and it will work just fine.

by (8,188 points)
0 votes

One of the reasons I replaced, in a recent project, an Area2D node by a TextureRect is that I needed to filter the mouse to stop the propagation of the input, control nodes can easily handle this, and I couldn't find a way to filter mouse input with an Area2D.

But Area2D can have a collision shape or polygon while TextureRect can only have a rectangle collision box.

There are surely a lot more differences that I'm not aware of.

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