How to Stop Vibrate for device

How to Stop Vibrate for device
0.0 0

#1

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


#2

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.


#3

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


#4

then set a flag

begin set flag, start vibrate

end set flag back, vibrate will end


#5

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


#6

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.


#7

is this method:
bool TouchScene::onTouchBegan(Touch* touch, Event* event)
{
int i=1;
if (i==1)
{
cocos2d::Device::vibrate(duration);
}
}
void TouchScene::onTouchEnded(Touch* touch, Event* event)
{
i=0;
}

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


#8

maybe something like this:

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

cocos2d::Device::vibrate(3);

}
void TouchScene::onTouchEnded(Touch* touch, Event* event)
{
cocos2d::Device::vibrate(0);
}

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


#9

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


#10

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


#11

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


#12

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.


#13

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.


#14

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


#15

Ha ha.
I have not thought about sex toy.


#16

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