Jump to content

  • Log In with Google      Sign In   
  • Create Account

Android Shake Method


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Cuajin   Members   -  Reputation: 155

Like
0Likes
Like

Posted 14 August 2012 - 07:20 AM

In my game I want the player to shake his phone, at any point during the game, and every shake will result in switching weapons.
Example: Player has knife, [shakes phone] and switches to a katana.

if (accelerometer.x >= 5 || accelerometer.x <= -5
   || accelerometer.y >= 5 || accelerometer.y <= -5
   || accelerometer.z >= 5 || accelerometer.z <= -5 )
	  switchWep();

This works, the problem is it has a side effect.When the player shakes the phone sometimes it switches weapons twice. So I want to limit it so that if there is a big shake the game doesn't switch from weapon 0 to weapon 2.

Please help.

Sponsor:

#2 Bluefirehawk   Crossbones+   -  Reputation: 1232

Like
0Likes
Like

Posted 15 August 2012 - 08:16 AM

I guess the problem is that he shakes for too long, and the phone registers the shake as a new action, thus your code is called again.

The simplest workaround would be that the switchWep(); uses timestamps when the weapon was switched the last time. When the timestamps have a smaller than for ex. 0.2 seconds difference, switchWep() does nothing.
Project: Project
Setting fire to these damn cows one entry at a time!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS