HTML5 Do Tilt functions works on HTML5/InstantGames

Discussion in 'GameMaker Studio 2 Community Tech Support' started by makas, Apr 14, 2019.

  1. makas

    makas Member

    Joined:
    Oct 15, 2016
    Posts:
    224
    As the title says I have a game on android and tilt functions works pretty well but, I can't make them work on html5, did html5/instant games works with tilt functions ?
     
  2. chmod777

    chmod777 Member

    Joined:
    Aug 26, 2016
    Posts:
    184
  3. makas

    makas Member

    Joined:
    Oct 15, 2016
    Posts:
    224
    Thanks I will check it out!
     
  4. makas

    makas Member

    Joined:
    Oct 15, 2016
    Posts:
    224
    I check it out is there any way to implement this on gamemaker? those functions looks like they are native to html5, but how do I bring those to gamemaker? sorry if this a very noobie question
     
  5. chmod777

    chmod777 Member

    Joined:
    Aug 26, 2016
    Posts:
    184
    You'll need an extension.
    Code:
    var g_tiltInit = false;
    var g_tiltAlpha = 0;
    var g_tiltBeta = 0;
    var g_tiltGamma = 0;
    
    function tilt_init() { // call this once on gamestart
       if(g_tiltInit) return;
       window.addEventListener("deviceorientation", function(event) {
           g_tiltAlpha = e.alpha;
           g_tiltBeta = e.beta;
           g_tiltGamma = e.gamma;
       });
       g_tiltInit = true;
    }
    
    function tilt_x() {
       return g_tiltBeta;
    }
    
    function tilt_y() {
       return g_tiltGamma;
    }
    
    function tilt_z() {
       return g_tiltAlpha;
    }
    Something like that... However, the values will not match those returned by the native device_get_tilt_* functions on Android and would need some additional stuff. But this should be possible.
     
    makas likes this.
  6. makas

    makas Member

    Joined:
    Oct 15, 2016
    Posts:
    224
    I appreciate your help I will look into this and comeback with the results
     

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