How to Stop Vibrate for device

How to Stop Vibrate for device
0.0 0


I use cocos2d::Device::vibrate(duration); to vibrate the device.
But Cocos, there is no stop function vibrating device.
Please, help me!


a work around could be to set a duration like: Device::vibrate(_duration);

Maybe repeat in a loop of some sort, when duration expires, vibration will stop.


I want to vibrate when touch Began and When TouchEnded Stop vibrate.
Please help me


then set a flag

begin set flag, start vibrate

end set flag back, vibrate will end


I don’t Know about flag.
Can you introduce me some document about flag?


a flag, a boolean or an int or whatever data type you want. I’d use 2, a boolean and an int.

int = duration
bool = false

pass in the int, set the bool in on touch end pass a zero to stop if the flag is still true, then set to false if needed.


is this method:
bool TouchScene::onTouchBegan(Touch* touch, Event* event)
int i=1;
if (i==1)
void TouchScene::onTouchEnded(Touch* touch, Event* event)

If this method. I used. But not efffect. Because cocos2d::Device::vibrate(duration) run when touchbegan


maybe something like this:

bool TouchScene::onTouchBegan(Touch* touch, Event* event)


void TouchScene::onTouchEnded(Touch* touch, Event* event)

I haven’t tested, just top of my head.


It is not effective either.
Is there any other method?
Please, help me


Perhaps you need to revise this concept. It can be annoying.


FYI Apple will not pass this, if you are targeting iOS.


Good point! I didn’t even look at the app submission guidelines. What is their reason?

I read an article that developers were making apps vibrate phones to compete in the sex toy market/experience. I, in a million years, never would have thought about doing this :slight_smile: I guess that is why I don’t have millions of dollars in my mattress.


As per my past experience you should only use vibrate on warning/error type of events (ex: game-over, collectables, btn press, etc).
Also must provide on/off button for vibrate in game.


Has anyone helped me solve this problem?
Thank you in advance.


Ha ha.
I have not thought about sex toy.


Thanks to @slackmoehrle , now we all thought about it. :smile: