Android Implementing Touch Screen Buttons?

Discussion in 'Programming' started by harambe1, Oct 11, 2018.

  1. harambe1

    harambe1 Member

    Joined:
    Aug 7, 2017
    Posts:
    25
    Guys I desperately need some help. I did not anticipate a simple system would be so hard to implement in GMS2. So I just bought mobile version and all is going great, my PC build has ported beautifully into android.

    NOW THE PROBLEM IS:
    I need to implement touch screen buttons to control my player. The main issue is that I cannot get the gui position accurately in relation to my current view. I have tried using this code:

    global.display_xscale = display_get_gui_width() / camera_get_view_width(view_camera[0])
    global.display_yscale = display_get_gui_height() / camera_get_view_height(view_camera[0])
    global.gui_mouse_x = (mouse_x - camera_get_view_x(view_camera[0]))*global.display_xscale
    global.gui_mouse_y = (mouse_y - camera_get_view_y(view_camera[0]))*global.display_yscale

    but it is still not getting me the correct position of my mouse at any given time.. I tested this by creating an object if I press mb_left and set the positions to global.gui_mouse_x and global.gui_mouse_y and the object is always being created from another point..

    Also, this might not be the best way to implement this system. So please if there is any better way to make touch screen buttons, please share it to me. I have spent all day looking for solutions and I cannot find anything that works for me. :(
     
  2. Morendral

    Morendral Member

    Joined:
    Jun 27, 2016
    Posts:
    307
    I think you are confusing how the gui layer works. It never changes position, it is always fixed with the top left always at 0,0. You don't need to use the camera references, you are better off using fixed percentages of window or display width/height
     
  3. harambe1

    harambe1 Member

    Joined:
    Aug 7, 2017
    Posts:
    25
    Yeah thanks mate, I already have working touch screen buttons now.. the only problem now is I can only press them one by one.. and I cannot do that with a platformer game.. I am still lost on how to implement multitouch for a platformer game..
     
  4. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    579
    Look up virtual keys and device input in the manual, which covers what you need more than likely.
     
  5. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    126
    Device input device number is like multiple attached mouses. If nothin is touched then first touch after that supposedly is device 0, and if it's held then next is device 1.
    Often for loop is used to cycle through to device 4 or something to see which one is where you need it.
     
  6. harambe1

    harambe1 Member

    Joined:
    Aug 7, 2017
    Posts:
    25
    Thanks! Found it now.. Should work like a charm :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice