I am looking to make an Xray/find the object game.
I have been messing around with masks but still can’t seem to find the right thing i’m looking for.
I’m still relatively new to game making and coding so i am very sorry if it seems like a dumb question.
i have been looking around online, youtube and the discord for some examples or tutorials and haven’t found much help.
This is what i’m trying to do:
When the spy glass passes over an object, the hidden object is only visible within the centre of the spy glass.
If it can be done via masking, is there a tutorial on how to use the masking function?
Thank you very much in advance for your help and patience.
So, static masking is very simple. Moveable masking is a bit more difficult.
The reason for this is because the way the mask extension works is:
The sprite (object will be masked) will only be visible if it is in a non-transparent portion of the other sprite (Sprite mask object).
Meaning with your magnifying glass, the box will only ever be visible if it is in contact with the blue area.
To make it do what you’re looking to do, you need to:
- Make a sprite object with an image that is much larger than your game screen (usually 4x larger. So if you have a 800x600 game you probably want an image that is roughly 1600x1600, which is pretty huge.
- Fill that entire image with a single solid color, like red. I’d name this like “ScreenMask”
- Cut out a hole (make a transparent area) in the center of this new sprite object that is the shape of the “hole” you want to use. This object will be hidden once you enable masking. In your case, you’d cut a circle slightly larger then the hole in the center of your magnifying glass.
- Using events, position this object so the hole is directly matching the hole of whatever visual sprite object you’re going to use. This might be easier if you make a point for the center of your spyglass hole, then use expressions so you’re doing "Change the Position of ScreenMask: set to SpyGlass.PointX(“Hole”)-(ScreenMask.Width()/2); SpyGlass.PointY(“Hole”)-(ScreenMask.Height()/2);
I’ve done a test with this and it seems to work okay.
Here’s the scene editor, I have an object behind the crate, and the mask object offscreen:
Here’s the preview with me mousing over the crate to show the object:
Here’s the events:
That is really helpful!! Thank you so much!!!