When clone is tapped

Hi I’m Dog Icing! Recently a lot of people have been asking for a way to refer to clones so I’m going to show you a way that I use in my projects to refer to clones.

  1. We’re gonna be using Last touch x and last touch y variables, however these aren’t redefinable, meaning that once tapped the function will execute forever. So, we’re going to create an object purely for fixing this problem. You can call this anything. In this example I’m going to call it X&Y.
    Now add the following code :
When (My Ipad)* is tapped {
  Set game variable** (X) to (Last touch X)
  Set game variable** (Y) to (Last touch Y)
}
image

That’s it for this object. Now to the more complex code.

  1. Go to the clone you want to use this on (this can be used on many clones at once) and add the following code note that when clone index = (number) is always executing so there is no need for
    “repeat forever”).
    Now we’re going to check whether the last touch is within the borders of the clone. To do this we’re going to use x and y positions. X and Y positions say give the x and y position of the center of a clone/object so we’ll add + self width ÷ 2, - self width ÷ 2, - self height ÷ 2, + self height ÷ 2. These will give us the borders of the object/clone.
    After you’ve got the check once if sorted, add your code and then, define the x & y to a location off the stage so objects can’t be affected/tapped there. In this example I’ve chosen -1 because it’s the first off the canvas and it’s the lord lol. Note: I think it is important to tell you that 0,0 is the lower left corner and anything less is off the stage, same as 100000, 100000 unless you’ve got a screen of 100000,100000. No matter the size of a screen, 0,0 or less will always be off the stage.
Check once if (X) > ((self x position) + ((self width) ÷ 2)) and (X) < ((self x position) - ((self width) ÷ 2)) and (Y) > ((self y position) + ((self height) ÷ 2)) and (Y) < ((self y position) - ((self height) ÷ 2)) {

[add your code to be executed]
Set game var (X) to (-1)
Set game var (Y) to (-1)
}
Image (highly recommended)

Now, keep in mind that you can now just copy and paste this code for when tapped for any clone. :slight_smile:

* if you’re using an iphone it’ll be when my iphone is tapped
** this must be a game variable to be accessible by different objects and clones. You could put ((xy object name) variable name) but game variables are much quicker.

Please let me know how you feel about this topic, constructive criticism is appreciated, and whether it worked.

- Dog Icing

11 Likes

Mm nice to hear that.

First post

5 Likes

hey, i might misunderstand what you are trying to teach, but isn’t this a easier way?

When Self is Tapped {
  If Clone Index = 0 {
    [Do whatever you want here]
  }
}
8 Likes

yes yes true true
thats what i use
(the easier way)

4 Likes

That’s if you want one big one, my one is for inside each clone

4 Likes

I think this is easier

4 Likes

what do you mean inside each clone

4 Likes

Inside each when clone index = (number)

4 Likes

so you mean you can check when even inside the check if

4 Likes

I find it’s simpler organising… when changing a code for a clone, you can change the tap at the same place instead of scrolling down somewhere

4 Likes

Yeah

4 Likes

nice
Thats cool

4 Likes

:slight_smile: check the second image… that should explain it

3 Likes

Yea that should be correct

4 Likes

@IcingPuppies

4 Likes

Thank you for this, this will be really cool for new users and also can be adapted for several other uses!

3 Likes

Here’s another way that I personally use
When self tapped
Check if clone index (a specific clone) or check if clone index bigger than 0 (all clones)

4 Likes

post i’m replying to, @Otato (:

2 Likes

@Otato

2 Likes

Oh

2 Likes