Incorrect Touch X, Y values on Android

Get help using Construct 2

Post » Thu Jul 04, 2013 2:48 pm

Hi,
I am getting incorrect Touch X, Y values on Samsung S Advance Android phone. Same code works on desktop using Mouse.X/Y but on this device if I use Touch X, Y most of the time I get value as 0. What could be going wrong ?

-Thanks
B
13
S
3
Posts: 76
Reputation: 1,679

Post » Thu Jul 04, 2013 3:16 pm

Have you tried to use Mouse.x("Layer") instead?
B
54
S
11
G
5
Posts: 101
Reputation: 7,247

Post » Thu Jul 04, 2013 3:25 pm

@nothaseo
He is talking about a touch problem, not mouse..

@mchulet
I can assume it's a mistake on your events, so, if you can reproduce it on a CAPX we could help better.
Image
B
104
S
23
G
17
Posts: 1,350
Reputation: 22,018

Post » Thu Jul 04, 2013 5:03 pm

There is a very simple explenation for this:

touch.x and touch.y only have a value while touching. If your finger is not touching the screen the value will be 0

Mouse.x and mouse.y however always have the value of where the mouse-pointer is regardless of if the button is clicked.

So when making something for a touch device, you should always be aware that there is only input while touching.


I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 05, 2013 4:17 am

@TELLES0808 I'll try to clear the non-necessary things and post capx file.

@LittleStain I am checking for values after touch.

-Thanks
B
13
S
3
Posts: 76
Reputation: 1,679

Post » Fri Jul 05, 2013 6:28 am

[QUOTE=LittleStain] ...

So when making something for a touch device, you should always be aware that there is only input while touching.

[/QUOTE]

@mchulet
You said checking after and as LittleStain stated there is only input while touching

so to workaround make an invisible sprite on touch at touch x,y then check values of the sprite after DrGreenThumbCAN2013-07-05 06:28:52
B
40
S
12
G
6
Posts: 136
Reputation: 6,347

Post » Fri Jul 05, 2013 11:23 am

@DrGreenThumbCAN thats exactly my current approach, if you'd want to test please just print the Touch.X & Touch.Y on Sprite drag start and see that you'd get 0,0.
B
13
S
3
Posts: 76
Reputation: 1,679

Post » Fri Jul 05, 2013 11:35 am

Works for me?

Ok this wasn't on drag start..

But you could ofcourse use on touch start instead..
Combine on touch start with is dragging, maybe?

Yep - touch start is dragging works..LittleStain2013-07-05 11:45:57
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 05, 2013 11:52 am

@mchulet,

It sounds strange, I know, but on sprite drag start seems to (sometimes?) fire before on touch start. But the touch start is dragging example seems to work every time..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 05, 2013 12:55 pm

@mchulet

A good workaround is setup a global variable to save the last Touch position, like one variable for touch.x and another to touch.y

Then, check the variable, and not the touch object.

This is the way I'm doing for my game.

http://goo.gl/1a3Jt

On the game, open the chrome console, click inside the game and press D, it will show you the debug, where you can see the lastest touch position.
Image
B
104
S
23
G
17
Posts: 1,350
Reputation: 22,018

Next

Return to How do I....?

Who is online

Users browsing this forum: ColombageEnPLS and 11 guests