BASIC

Author Topic: Shake my iphone?  (Read 2270 times)

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Shake my iphone?
« on: 2011-Jan-14 »
Does someone has a function to detect if the iPhone has been shaked?

Thank you.
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1542
    • View Profile
Re: Shake my iphone?
« Reply #1 on: 2011-Jan-14 »
That's something I have wondered about lately also (for a magic eight ball style app).

When shaken (not "shaked" or stirred) I'd imagine just toggling the extremes although haven't tried any yet. Wouldn't it be just a case of measuring the sensor change amounts? What a x,y,z graph look like?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Shake my iphone?
« Reply #2 on: 2011-Jan-14 »
I'd test for X > 1.5

Offline phaelax

  • Mc. Print
  • *
  • Posts: 36
    • View Profile
Re: Shake my iphone?
« Reply #3 on: 2011-Jan-29 »

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1542
    • View Profile
Re: Shake my iphone?
« Reply #4 on: 2011-Jan-29 »
Something like this works for me:
Code: GLBasic [Select]
// shakey shakey
FUNCTION shake_input:
        IF oMouse[0].xjoy<-0.25 AND shake_toggle<>-1
                shake_toggle=-1
        ENDIF
        IF oMouse[0].xjoy>0.25 AND shake_toggle<>1 OR KEY(KEY_SPACE)
                shake_toggle=1
                INC shake_count,2
                IF shake_count>10
                        shake_count=0
                        // shaken
                ENDIF
        ENDIF
        IF shake_count>0
                LOCAL temp_sin=SIN(GETTIMERALL())
                IF temp_sin>0.99
                        DEC shake_count
                ENDIF
        ENDIF
ENDFUNCTION
 

Also:
ALPHAMODE shake_count/10.0 /// in loop for fade-out