Touch. Shake device

0 favourites
  • 12 posts
From the Asset Store
A futuristic device, can be used as radarscreen, optionscreen, infodisplay, research device, ...
  • Hi

    i'm building a small game and i wish to enable (shake device) to invoke a particular action.

    i've been struggling with touch.accelerometer with no success.

    in the game i want the player to be able to shake their phone to use a power up.

    any help appreciated

  • sorry i meant touch.acceleration

  • i was curious to know how to do it as well but seems nobody knows ?

  • shiprat odesign : do you known in advance what kind of gesture you want the user to do ? If it's a shake, do you know how much shake you want to have, and on which axis ?

  • I think z axis movement not sure on speed. Just a quick up/down movement.

  • same answer here, same way as you shake a bottle so it could be even y axis

  • anyone have news about this topic ?

  • I know this is an old thread, but did anyone ever figure this out?

    I'd love to add an action when you shake the phone in an app I'm working on.

  • Ironically I was going to ask a similar question.

    I experimented with a layout that shows X Y and Z output from the touch.accelerometerx, y , and z (without gravity - not sure of the difference) in three text fields, but the resulting data does into several decimal points. I suppose I ought to use an integer of the output?

    FYI: X is left and right movement, Y is up and down movement, and Z is towards and away from you.

    I see my users performing a left-right shake gesture, which will fill a progress bar and ultimately trigger returning to the original layout.

    What I would like is any suggestions regards measuring the rate of change - from the X axis data. 4.0x seems to be a comfortable point, (and I don't want users to inadvertently fling their phones across the room). So - thoughts on measuring this accumulated 'shake' data?

    Any input is welcome and appreciated!

    • Scott
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've been experimenting with this a little. I'm currently unable to test on a physical device so I'd love some feedback, but everything seems to be working great in the simulator.

    The basic idea is to check the X, Y and Z values (Acceleration) every so often (POLLINGINTERVAL) and compare to the last check to see if they've increased a significant enough amount (SENSITIVITY) and have also met a minimum acceleration (MINACCEL). I just created a group called Shake Detection, added some local variables to track the current values, global values to detect the previous values and some local constants to let me easily tweak things. To let my game know if I've detected any shaking I set the global variable IsShaking to 1. Here's a screenshot of my events/actions:

    Looks like I can't post links yet, so add the http:// to the following "link" to see the image:

    To use this, I just create another System Event (Compare Variable) and check if IsShaking = 1. If it does, the first thing I do is set IsShaking = 0 and do whatever action(s) I wanted.

    This is just what I came up with. If anyone has any suggestions or tweaks, please let me know! Thanks!

  • Thanks a lot for this guide!

    One question though: how would you determine the shake sensitivity?

    In theory - i think - it should be something like dividing the current values with the last values but my problem are the negative values of the axis.

    Can you help me out?

    Hugs and greetings from this corner of the world.

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