0 votes

I want to create sprite masks but I want to reveal another sprite when I hover my mouse over a sprite. Here is the video of the same but in Unity: https://www.youtube.com/watch?v=4pl8DcsCQ_k

I tried using mask in light 2d but I couldn't proceed any further since I am still a beginner to game development

asked Apr 17 in Projects by rAyMaX (17 points)

2 Answers

0 votes

You can do it with a scene comprised of 2 sprites and an Area2D node. Give the Area2D a child of CollisionObject2D and set it's shape to a rectangle covering the sprites so that everything is overlapping.

Add an empty script to the scene root Node2D. Then connect the mouseentered and mouseexited signals of the Area2D to the script.

Then add getchild(1).hide() and getchild(1).show() to each of the script functions that handle the signals.

Now the top-most sprite will toggle it's visibility on/off as the mouse moves over it. Save the scene and instance it in other scenes where you need it.

You can add export vars for textures to set the sprite textures later when you instance the scene in other scenes.

answered Apr 18 by backendcoder (20 points)
+1 vote

Take a look at my answer over here.

answered Apr 18 by njamster (9,522 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 How to use this Q&A? before posting your first questions.