H.D.I calculate the absolute position relative to the canvas

Get help using Construct 2

Post » Tue Jul 07, 2015 11:52 am

Hi Folks,

I use the following simple formular to calculate the absolute positon of a touch relative to the size of the canvas window:

Code: Select all
Touch.AbsoluteX/(WindowWidth/1280)

screenshot: http://gyazo.com/55bf28b8fceb6c3767333e788df5e85d
(my project is 1280 px width)

which works like a charm on my desktop in every possible window size!

the problem is it does not work on mobile! for example if i test on my z1 compact (which has a 1280px width screen) the most right position is displayed with 640. which is exact halv. but the formular should return 1280/(1280/1280) = 1280!
i am helpless here :( ive get similar results if i test on my s2... but on desktops i can resize windows as i want, everything gets calculated fine with every windowsize...

Kind Regards
Patrick
B
19
S
7
G
1
Posts: 222
Reputation: 2,551

Post » Tue Jul 07, 2015 8:59 pm

as i couldnt find a solution i replaced the slider with 2 buttons and simple is in touch... but i would to know if there is an solution for future projects :)

Regards
Patrick
B
19
S
7
G
1
Posts: 222
Reputation: 2,551

Post » Tue Jul 07, 2015 9:23 pm

Couldn't you just use touch.X instead of converting touch.absoluteX?

Touch.x gives you the x on the layout.
You can also use Touch.X("layer") to get an x relative to a layer. If you want a position on a hud layer that doesn't scroll, this would do it.


If you're intent on finding why
Touch.AbsoluteX/(WindowWidth/1280) is equal to 640 instead of 1280, take a look at the values of Touch.AbsoluteX and WindowWidth. It could be a high dpi feature of your mobile or something of that effect. There's a project setting for that that you could probably fiddle with.
B
94
S
33
G
113
Posts: 5,354
Reputation: 73,269

Post » Sun Jul 12, 2015 3:01 pm

@R0J0hound Touch.X("layer") that would have been the solution! didnt know about this function though :(

Thank you so much for helping me out here!
Kind regards
Patrick
B
19
S
7
G
1
Posts: 222
Reputation: 2,551


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 8 guests