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

0 favourites
  • 4 posts
From the Asset Store
Pixel Destruction like in "Worms" (Drawing Canvas based)
  • Hi Folks,

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

    screenshot: [url=http://gyazo.com/55bf28b8fceb6c3767333e788df5e85d]http://gyazo.com/55bf28b8fceb6c3767333e788df5e85d[/url]
    (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 <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad"> 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 
  • 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



  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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


Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)