Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBCullis

Posted 18 February 2013 - 09:54 AM

Or another option (to strictly fire once per trigger pull):

 

Keep two GamePadStates, "current" and "previous".

Every frame, push current to previous, and then update current from GamePad.GetState().

 

previousState = currentState;

currentState = GamePad.GetState(PlayerIndex.One);

 

Then only shoot if the trigger is "freshly" pulled, but not if it's being held down.

 

float currentRightTriggerValue = currentState.Triggers.Right;

float previousRightTriggerValue = previousState.Triggers.Right;

 

if(currentRightTriggerValue == 1 && previousRightTriggerValue == 0)

{

    Shoot();

}

 

I've found that creating an inputManager to do comparison checks like these for any button is IMMENSELY helpful.  Then this whole mess can be wrapped in a method call like

 

if(inputManager.IsTriggerJustPulled(Triggers.Right))

{

    Shoot();

}


#1BCullis

Posted 18 February 2013 - 09:52 AM

Or another option (to strictly fire once per trigger pull):

 

Keep two GamePadStates, "current" and "previous".

Every frame, push current to previous, and then update current from GamePad.GetState().

 

previousState = currentState;

currentState = GamePad.GetState(PlayerIndex.One);

 

Then only shoot if the trigger is "freshly" pulled, but not if it's being held down.

 

float currentRightTriggerValue = currentState.Triggers.Right;

float previousRightTriggerValue = previousState.Triggers.Right;

 

if(currentRightTriggerValue == 1 && previousRightTriggerValue == 0)

{

    Shoot();

}


PARTNERS