Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

closed as off topic by Josh Petrie, bummzack, Byte56, ClassicThunder, eBusiness Apr 20 '13 at 12:25

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

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

2 Answers 2

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);
share|improve this answer
    
Thanks for your reply i will try this. –  Maan Apr 13 '13 at 5:43

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.

share|improve this answer

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