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
Gamepad button repeat delay
Moderator: Moderators
Gamepad button repeat delay
- Attachments
-
- ButtonRepeatDelay.zgeproj
- Same as RepeatDelay of KeyPress component, but for the gamepad buttons.
- (1.86 KiB) Downloaded 934 times
Re: Gamepad button repeat delay
Hi Ats,
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.
K
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:Can you guys tell me if the logic is good/optimized before I duplicate this to my game?
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.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?
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.
K
- Attachments
-
- DelayedRepeat.zgeproj
- Press "D" to demo :-)
- (1.16 KiB) Downloaded 898 times