Best way to detect the click/touch in some parte of the sprite image

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:

The advantage of method #2 is that if the equipament sprite were moved, the points will too.

But I find the way #2 not much efficient, painful to do. Is there another and better way to do that??


1 Like

Methode 1 is ok. You may use a colored panel sprite with good sizes and hide it at the beginning of the scene for making it invisible.

For clicking on sprite you may do this (look just at the left/condition part):


Right. But is there any easy way to move the sprite together with the equipament? Because my equipament is draggable…

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

1 Like

I’d actually recommend combining #1 and #2.

  1. 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).
  2. Create all of the points on your main sprite object. Number them instead of giving them names.
  3. Add the correct number of the red box/invisible sprites.
  4. Add instance variables named “ID” to each.
  5. 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)
  1. 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)
  1. 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.