Img. Set on touch

108 views
Skip to first unread message

Sanya Exclusive

unread,
Aug 23, 2018, 2:55:29 PM8/23/18
to DroidScript
How to apply coordinates to the image so that when you click on a certain part of the picture, some functions are performed

alex.symbroson

unread,
Aug 23, 2018, 3:06:38 PM8/23/18
to DroidScript
in the OnTouch callback function you get an event object as first argument which you can use to determine the touch position(s), the action and the source.

easiest would be to use the X and Y properties because they represent the first touch position.
then you can do a simple point-rect collision to determine whether the user touched a specific area on the image.

area = {
    x1
:0.2,
    y1
:0.3,
    x2
:0.7,
    y2
:0,3
}

function ImgOnTouch(ev) {
   
if(ev.X > area.x1 && ev.X < area.x2 &&
       ev
.Y > area.y1 && ev.Y < area.y2) {
        app
.ShowPopup("area touched");
   
}
}

Stephan Stadler

unread,
Jun 17, 2021, 9:51:13 AM6/17/21
to DroidScript
How to do, if the point of collision is not an area, but an botton or an image?

Steve Garman

unread,
Jun 17, 2021, 10:04:08 AM6/17/21
to DroidScript
I'm not sure I understand the question

Are you looking for something more complicated than checking that ev.Y is greater than a large number like 0.9 ?

Stephan Stadler

unread,
Jun 17, 2021, 10:12:25 AM6/17/21
to DroidScript
The area in the example above ist exactly defined.
How can i detect a collision, if it is not a defined area, but any other object?

Steve Garman

unread,
Jun 17, 2021, 10:19:29 AM6/17/21
to DroidScript
Collision detection is a bit off-topic for this thread

I recommend tou start a new thread and explain what you are starting with and what you want to achieve
Reply all
Reply to author
Forward
0 new messages