I am using AndEngine to develop an Android game and I want vibration to be triggered when an enemy hits a player.
How can I implement this into my game?
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
Add this permission to your Manifest.xml file
<uses-permission android:name="android.permission.VIBRATE" />
and when there is a collision or something like that (I assume that you're handle the collision detection with AndEngine)
you can add this code :
// this is how you get an instance of Vibrator from current Context Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // this is how you set the vibrate time (its in milliseconds, so if you want it // to vibrate for 1 sec - write 1000 v.vibrate(300);
You can find the API documentation for the Vibrator here. To determine if the player is hit by an enemy you should lookup a decent tutorial on how collision is handled in AndEngine and add the vibrator code to the collision handler.