GLBasic forum

Codesnippets => Code Snippets => Topic started by: ampos on 2011-Jan-14

Title: Shake my iphone?
Post by: ampos on 2011-Jan-14
Does someone has a function to detect if the iPhone has been shaked?

Thank you.
Title: Re: Shake my iphone?
Post by: matchy 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?
Title: Re: Shake my iphone?
Post by: Kitty Hello on 2011-Jan-14
I'd test for X > 1.5
Title: Re: Shake my iphone?
Post by: phaelax on 2011-Jan-29
I'm not sure if this can help you in GLB, but: http://stackoverflow.com/questions/150446/how-do-i-detect-when-someone-shakes-an-iphone (http://stackoverflow.com/questions/150446/how-do-i-detect-when-someone-shakes-an-iphone)
Title: Re: Shake my iphone?
Post by: matchy 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