Select part of an image not the whole thing?
KEE4
www.chriskieffer.comLos AngelesMember Posts: 65
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.
Comments
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.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
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
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.
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.
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.
Going to try this now, thanks! Ill let you guys know if that works.
I found an easy way to kind of cheat it. Thanks to your help.
I just added the rules
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.
I can't post a video here it won't let me. Sorry
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.
Ok great! Thanks again!