#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Select part of an image not the whole thing?

www.chriskieffer.comLos AngelesPosts: 65Member

Is there a way to "When touch is pressed "WITHIN THESE PIXELS" etc etc?
Like if I had a png that is 100x500 pixels.
I want to be able to touch different areas of the png to trigger separate things like...
100x250 area triggers... 100x250 area triggers.... etc I hope that makes sense.
Thanks for any suggestions.

• ImagineLabs.rocks Posts: 5,426Member, BASIC

I think your best bet will be to create the full image out of smaller images that each have their own action.

Another option would be to use one large image with no actions applied and then place invisible actors over the large one, each with the appropriate actions applied.

• www.chriskieffer.com Los AngelesPosts: 65Member

Thats what I was avoiding because its a scrollable list. As you scroll up and down the list you can click on a name or change the name. I built it already with the scroll and on/off states, but.... I will make an image to better describe it. BRB

• London, UKPosts: 1,893Member
edited February 2016

You could try subtracting the Mouse.Position from the Self.Position of the actor. So for example if your actor was in the middle of the scene at X = 384 and your Mouse was X = 280 the difference would be

Mouse.Position.X (280) - Self.Position.X (384) = -104
That means that you've clicked 104 pixels to the left of the center of the actor.

Clicking past the center of the actor say X = 450 would be:
Mouse.Position.X (450) - Self.Position.X (384) = 66
A positive number means you've clicked 66 pixels to the right of the center of the actor.

You can tie this formula in with the if touch is pressed and then check for >= and <= to create your hotspots

I think that would work. It might be a bit fiddly with lots of different areas.

• www.chriskieffer.com Los AngelesPosts: 65Member
• London, UKPosts: 1,893Member
edited February 2016

Based on your image and my example it might go a little like this:

If touch is pressed and (Mouse.Position.X - Self.Position.X) >= 125 and (Mouse.Position.X - Self.Position.X) <= 250

This is based on your image being 500 pixels wide like you say and I estimated that the checked in button is probably about 125 pixels wide and starts 125 pixels from the center.

If the checked in button starts further than 125 pixels from the center, say 150 then just change the first number in the if statement above.

• London, UKPosts: 1,893Member

For the hotspot on the left (missed that one)

If touch is pressed and (Mouse.Position.X - Self.Position.X) >= -250 and (Mouse.Position.X - Self.Position.X) <= -230

This is assuming the hotspot needs to be 20 pixels from the left of the image.

• www.chriskieffer.com Los AngelesPosts: 65Member

Going to try this now, thanks! Ill let you guys know if that works.

• www.chriskieffer.com Los AngelesPosts: 65Member

I found an easy way to kind of cheat it. Thanks to your help.
1. if touch is pressed - Inside
2. If attribute self.motion.linearvelocity.y <= 5 "so you can't check or uncheck while the list is scrolling"
3. If attribute Mouse.position.x >= 535

so i just vertically sliced the image and it works. Ill put up some screen shotsand a video to show what I did. Thanks again guys.

• www.chriskieffer.com Los AngelesPosts: 65Member

• www.chriskieffer.com Los AngelesPosts: 65Member
• www.chriskieffer.com Los AngelesPosts: 65Member

I can't post a video here it won't let me. Sorry

• London, UKPosts: 1,893Member

Glad you've got it to work!

You would only need to check for the Self.Position.X and Mouse.Position.X if the actor ever changes position along the X axis. If it's always in the same position then what you've done would be fine.

• www.chriskieffer.com Los AngelesPosts: 65Member

Ok great! Thanks again!