Access the accelerometer on Windows Phone 8

0 favourites
  • 8 posts
  • I'm having trouble getting the accelerometer to work. All the touch expressions return 0 and the infinite jumping sample project doesn't even work.

    Is there are way to get it to work? Or is this simply a feature not yet implemented in Construct 2?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It does support accelerometer (but not the 'with G' expressions) and inclinometer in Windows 8 apps, but only if the device has support for them.

  • Ashley I thought Windows Phone 8 doesn't support accelerometer?

    Panacea if you post a request in my Windows Phone plugin thread I can take a look into it (won't be for a couple of weeks I'm afraid as I'm out the country).

  • The IE engine doesn't support the standardised motion or orientation events yet, so we added support in the Touch plugin to use the Windows 8-app specific libraries to detect motion and orientation. However that will only work if the device has the necessary hardware.

  • Well, my device is a Lumia 820 so my assumption is that it does support orientation. The accelerationXYZ expressions in the touch object return 0. How do I access this "inclinometer"?

  • It does not work for me too. Just tried the sample jump project, the phone just vibrate when I tilt it.

  • Hi all, I had the same problem and I found a workaround to access accelerometer data. Unfortunately Microsoft doesn't support standard HTML5 deviceorientation and devicemotion events, so you have to deal with deep code changes in your visual studio project.

    The following code snippets are simply a workaround to pass accelerometer data from C# code to the webbrowser control in an extremely unelegant way. You may notice some performance drop and you'll have to deal with trigonometry to obtain correct values from sensors.

    I needed only touch.beta values on a landscape app, if you are familiar with Visual Studio and Trigonometry you can mod this code to obtain also alpha and gamma values.

    1) Export your game as a Windows Phone 8 project without minifying the script.

    2) Open Mainpage.Xaml in VS2012 and add the following line before the end of the tag phone:WebBrowser


    3) Open Mainpage.Xaml.cs and search for this.

       public void OnAppDeactivated()


                Browser.InvokeScript("eval", "if (window.C2WP8Notify) C2WP8Notify('deactivated');");


    Add this snippet under these lines of code.

    private void Browser_ScriptNotify(object sender, NotifyEventArgs e)


                if (e.Value == "startAccelerometer")


                   if (accelerometer == null)


                        accelerometer = new Microsoft.Devices.Sensors.Accelerometer { TimeBetweenUpdates = TimeSpan.FromMilliseconds(100) };

                        accelerometer.CurrentValueChanged += (o, args) => Dispatcher.BeginInvoke(() =>


                            var x = args.SensorReading.Acceleration.X;

                            var y = args.SensorReading.Acceleration.Y;

                            var accbeta = (Math.Atan2(-x, y) * 180.0 / Math.PI) - 90;

                            Browser.InvokeScript("eval", string.Format("accelerometerCallback({0})", accbeta));






    4) Open index.html and replace tag <body> with <body onload="onLoad()">

    5) Open c2runtime.js and add on top these lines

    var wp8_beta = {};

    function onLoad() {



    function accelerometerCallback(accbeta) {

          wp8_beta = accbeta;


    6) Find on c2runtime.js the line

    return this.orient_beta;

    and replace with

    return wp8_beta;

    Now you'll have touch.beta values correctly passed from wp8 to your game.

    Since I suck at trigonometry I hope someone will mod the code to obtain also alpha and gamma values.

  • And how does it now works in VS 2013 with universial +8.1 apps?

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