Vibrator Lag


Last Updated:

  1. Kailas

    Kailas Member This Topic's Starter

    Joined:
    Aug 25, 2010
    Messages:
    19
    Likes Received:
    0
    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.
     

    Advertisement
  2. tencent

    tencent Member

    Joined:
    Oct 1, 2010
    Messages:
    15
    Likes Received:
    0
    To keep it clean why not put the vibrator into its own class and have its thread itself? As for the vibrator causing delays, I have never noticed it however the only times I have used it outside of notifications is on menu presses and to notify the user that a screen shake worked and there was no lag that I was aware of. That said it could be a phone specific issue where it just take an abnormally long time for the vibrator service to respond. In which case you most certainly want to try threading to see if its a solution otherwise you are going to have angry users.
     
  3. Kailas

    Kailas Member This Topic's Starter

    Joined:
    Aug 25, 2010
    Messages:
    19
    Likes Received:
    0
    Well I just made the vibrator into its own thread and to my annoyance; it had no effect at all on the lag.

    Does anyone have any other ideas?
     
  4. Sam Voss

    Sam Voss Well-Known Member

    Joined:
    Jun 25, 2010
    Messages:
    367
    Likes Received:
    44
    first off, Just a suggestion, but try changing the time on the vibration, do a short one, and a long one, does it change the lag time? this could tell us either A, its waiting for the vibrate to be done before game continue, or B, the phone lags a little bit on Vibrate.
     

Share This Page

Loading...