I'm basically trying to recreate the inventory from resident evil 4. Right now I have every block as its own scene with the root node being an Area2D, and Sprite2D and CollisionPolygon2D nodes as children. I wrote a script to be able to select and move each block in the main scene and attached the script to each block. I thought doing this would create separate instances of the script, but when I test it in the main scene, all the blocks become selected no matter where I click on the screen and they all move at the same time. I've tried using the event.position in the _input function to check if it's equal to the object position, and I've tried using the mouse_entered signal from the Area2D node, but nothing seems to be working
#How can you create instances of a script?
1 messages · Page 1 of 1 (latest)
all you're doing is checking if you clicked
you're not checking where you clicked, or on what you clicked.
Area2D has a couple signals that can help you with that, namely mouse_entered and mouse_exited
so you could set a boolean flag to true when mouse_entered happens, and set it to false when mouse_exited happens.
then in your clicking routine, you can check for this flag and see if it's true. if it is, then the mouse is hovering over this particular card and only then do you accept that you can click on it.
you also have overrideable methods that do the same thing, namely _mouse_enter() and _mouse_exit(), if you prefer going through callbacks instead of signals
other techniques for this would be to use a raycast to determine what's underneath the mouse when you click, and then check if the card that comes back is the card that's currently processing