2
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ What did you try so far. Where do you run into problems? \$\endgroup\$ – Hennes Apr 12 '13 at 9:30
  • 2
    \$\begingroup\$ might be better on SO because this is android specific (and it has been asked there a few times already) \$\endgroup\$ – ratchet freak Apr 12 '13 at 10:00
4
\$\begingroup\$

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);
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.