Gamepad button repeat delay

Share your ZGE-development tips and techniques here!

Moderator: Moderators

Post Reply
User avatar
Ats
Posts: 716
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Gamepad button repeat delay

Post 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 ;)
Attachments
ButtonRepeatDelay.zgeproj
Same as RepeatDelay of KeyPress component, but for the gamepad buttons.
(1.86 KiB) Downloaded 934 times
User avatar
Kjell
Posts: 1911
Joined: Sat Feb 23, 2008 11:15 pm

Re: Gamepad button repeat delay

Post 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
Attachments
DelayedRepeat.zgeproj
Press "D" to demo :-)
(1.16 KiB) Downloaded 898 times
User avatar
Ats
Posts: 716
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Post by Ats »

Thanks Kjell, very useful !
But I'll use it the opposite way: 3 rapid fire shots and then slow fire mode ;)
Post Reply