How to show another sprite when hover mouse over a sprite?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rAyMaX

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

:bust_in_silhouette: Reply From: backendcoder

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 mouse_entered and mouse_exited signals of the Area2D to the script.

Then add get_child(1).hide() and get_child(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.

:bust_in_silhouette: Reply From: njamster

Take a look at my answer over here.