Hi guys!
I have a sprite that is an image of an equipament. I would like to detect when the user touchs/click in some specifics parts of this image, doing different things. What is the best way?
I tried two things:
#1: creating an empty sprite, giving it a size and positioning above the equipament sprite, in the position I want to detect the clicks/touches. And than, add an event to detect the click on this empty sprite. But it doesn’t work and nothing happened.
#2: creating points in the sprite (Edit Points, I called this point “OFF”) and checking the coordenates, putting a tolerance, as the image below:
You have already created the point OFF.
When the multimeter is dragged, put the position of the sprite around the point OFF, in thi way the sprite will follow the multimeter
Create a red box sprite (sprites have to have an image to have a hitbox), or create a transparent image and import it as a sprite (This will still count).
Create all of the points on your main sprite object. Number them instead of giving them names.
Add the correct number of the red box/invisible sprites.
Add instance variables named “ID” to each.
To ensure you can add more points if you need to later, create an event
At the beginning of the scene|
---(Subevent) For Each Redboxsprite | Modify Scene Variable "Count": Add 1
| Modify Redboxsprite.ID = Variable(Count)
Create an event (no condition)
For Each Redbox Sprite
| Change the Position of Redboxsprite: set to Multimetro.PointX(ToString(Redboxsprite.Variable(ID))) (x axis), set to Multimetro.PointY(ToString(Redboxsprite.Variable(ID))) (y axis)
Then you can use the “if RedboxSprite.ID = 1/2/3/4/5/etc” condition along with your “click” conditions to target a specific redboxsprite and action.
Edit: If you are not worried about potentially increasing your number of sprites later, your original idea for #1 is correct. You just have to have an image. Even if it’s a red box, you can just add a “at the beginning of scene | Hide spritename”. It’ll make it invisible.