Hi everyone.
I've just implemented vibrations in my game. The problem I'm having is that almost every time it vibrates; the game lags and everything jumps over about half a second.
Here's the relevant code:
//member variable
Vibrator mVibrator;
//class constructor
mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
//when the player gets hit
//damage is passed into the function as the amount of damage they took.
mVibrator.vibrate((long)(damage * 1000));
The only reason I could think of that would cause this is if the phone has to wait for the vibrator to finish ... which would be odd but not impossible. Does anyone know why it does this or a way around it? I would assume that putting the vibrator in its own thread would work but I'd rather not make a separate thread for it if i don't have to.
I've just implemented vibrations in my game. The problem I'm having is that almost every time it vibrates; the game lags and everything jumps over about half a second.
Here's the relevant code:
//member variable
Vibrator mVibrator;
//class constructor
mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
//when the player gets hit
//damage is passed into the function as the amount of damage they took.
mVibrator.vibrate((long)(damage * 1000));
The only reason I could think of that would cause this is if the phone has to wait for the vibrator to finish ... which would be odd but not impossible. Does anyone know why it does this or a way around it? I would assume that putting the vibrator in its own thread would work but I'd rather not make a separate thread for it if i don't have to.