Page 1 of 1

Gamepad button repeat delay

Posted: Thu Feb 27, 2014 12:08 am
by Ats
I just made a little snippet in order to reproduce the RepeatDelay option of the KeyPress component so that the buttons on a gamepad can work the same way.

For the exemple:
Pressing the Spacebar will produce a cube on the left with the usual RepeatDelay option set to .5
but it also produces a cube on the right with no RepeatDelay being set. The same bit of code is used for the button 0 of the gamepad.

Can you guys tell me if the logic is good/optimized before I duplicate this to my game?

By the way, how (but it's more a "where") can I write a function to be called instead of duplicating the same code twice on the space bar and the gamepad button?

Thanks ;)

Re: Gamepad button repeat delay

Posted: Thu Feb 27, 2014 12:56 am
by Kjell
Hi Ats,
Ats wrote:Can you guys tell me if the logic is good/optimized before I duplicate this to my game?
Instead of maintaining GameTime and syncing up ButtonTimer, simply maintain ButtonTimer and set it to 0 when the conditions are met. That way you also won't run into precision issues ( when your game is running for a long time ).
Ats wrote:By the way, how (but it's more a "where") can I write a function to be called instead of duplicating the same code twice on the space bar and the gamepad button?
You can either use a ZLibrary ( in App.Onloaded ), or call a named ZExpression ( in Content ) using CallComponent. Personally i prefer keeping a Array with "virtually" mapped input, and write code on top of that though.

And in case you want to replicate keyboard-style delayed repeat behavior ( often used for navigation purposes in console games ), i usually go with the attached approach.

Image

K

Posted: Fri Feb 28, 2014 9:32 am
by Ats
Thanks Kjell, very useful !
But I'll use it the opposite way: 3 rapid fire shots and then slow fire mode ;)