Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
please explain how to work with accelerometer — Gideros Forum

please explain how to work with accelerometer

konstantinkonstantin Member
edited October 2011 in General questions
hello, I am totally new and I am trying to figure out how to respond to accelerometer events such as device shaking. In Corona SDK they have an event for this, is it implemented in Gideros? Also, in the player I see no option to emulate device shaking, do you have plans to add this?
Tagged:

Comments

  • atilimatilim Maintainer
    edited October 2011
    Hi,

    you can get the coordinates of the accelerometer by calling
    local x,y,z = application:getAccelerometer()
    Unfortunately we don't have direct support for shake detection. But it's also very easy to implement. Today, I can post an example here.

    We don't put this option to desktop version of Gideros Player because you can test your application on real device immediately. You can deploy GiderosiPhonePlayer.zip (which comes with the insallation) to your iOS device, then press play and shake it :)
  • gorkemgorkem Maintainer
    edited October 2011
    A detailed overview of how to deploy Gideros Player to iPhone or Android, use the related Wiki entry here:

    http://www.giderosmobile.com/DevCenter/index.php/Deployment

    Once you deploy the player to your device, you'll rarely need the Player on your desktop as you'll be able to test your app immediately on your real device.

    Let us know in case you have a problem with this.
  • konstantinkonstantin Member
    edited October 2011
    thanks. now that you have mentioned deployment: I do not have to have the player installed on the devices, of course, when I distribute my app to the users. this is only for development, right? your sdk can compile Lua to native code, right?

    @atilim, an example would be very useful.

    regarding testing on a real device: it would be nice, but one of the reasons why I am looking at gideros sdk is because it promises me an ability to develop for iOS/Android using windows and a device simulator. I do not have the devices (yet), I would like to develop my app first and then see how it goes to justify buying the device(s).
  • gorkemgorkem Maintainer
    You do not have to have a device for development, as you mentioned. :) When you are comfortable with the progress of your app, you may choose a device for testing.

    Yes, Gideros Studio compiles your Lua code to native code.

    Feel free to share your progress here :) We'd be glad to know.
  • Hi,

    you can get the coordinates of the accelerometer by calling
    local x,y,z = application:getAccelerometer()
    Unfortunately we don't have direct support for shake detection. But it's also very easy to implement. Today, I can post an example here.

    We don't put this option to desktop version of Gideros Player because you can test your application on real device immediately. You can deploy GiderosiPhonePlayer.zip (which comes with the insallation) to your iOS device, then press play and shake it :)
    hi, Is shake detection supported now?
  • ar2rsawseenar2rsawseen Maintainer
    Here is a really quick a not so sophisticated method of detecting shakes:
    require "accelerometer"
     
    accelerometer:start()
     
    local last_x = 0
    local last_y = 0
    local last_z = 0
     
    local interval = 100
     
    local threshold = 500
     
    local function detectShake()
    	-- get accelerometer values
    	local x, y, z = accelerometer:getAcceleration()
     
    	local speed = math.abs(x+y+z - last_x - last_y - last_z)/ interval * 10000;
    	if(speed > threshold) then
    		print("shaking")
    	end
    	last_x = x;
    	last_y = y;
    	last_z = z;
    end
     
    local timer = Timer.new(interval)
    timer:addEventListener(Event.TIMER, detectShake)
    timer:start()
    I don't know maybe there's something better available, but it kind of does what it needs. You can adjust threshold to suit your need.

    Likes: atilim

    +1 -1 (+1 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    I think there is no internal Gideros shake detection only because Atilim is pretty stressful about code optimization. And shake event would only be another task that will be checked on every iteration, consume resources, and rarely used. :D

    Likes: atilim

    +1 -1 (+1 / -0 )Share on Facebook

  • Yes, Gideros Studio compiles your Lua code to native code.
    Huh??? New feature? From what I know, just like C*r*na, it compiles your Lua code to Lua bytecode and binds it with the framework into a native app project. How you said it, it would translate/compile LUA into Objective-C on IOS and JAVA on Android. I would be totally surprised if it does.

  • ar2rsawseenar2rsawseen Maintainer
    edited March 2012
  • hi @ar2rsawseen
    thanks for your code!
    It's a really quick method but not so efficient,it would be best if gideros sdk support shake detection nativly.
    Maybe use UIEventSubtypeMotionShake event, I am not sure.
  • ar2rsawseenar2rsawseen Maintainer
    Well, if you need IOS you can always use plugins.

    But how about polls and votes? How democratic is (cough)Atilim(cough), ehmm, Gideros?
  • Shake detection is hard. Before Apple released their API I spent several days on it and never did find what I wanted (nuanced shake detection). A shake while riding in a bus or walking is not the same as a shake while sitting on a stable chair. I don't like Apple's method for finding shakes either. For some reason it never works when I actually want it but always works when I don't want it.

    Likes: gorkem

    +1 -1 (+1 / -0 )Share on Facebook
  • ZoytZoyt Member
    It's in the roadmap... It can't be that hard.... Can it?
Sign In or Register to comment.