I've implemented a jump buffer feature in my game, but I've encountered an issue: when I hold down the "d" key to move right, any jump triggered within the jump buffer window doesn't register until I release the "d" key. I'm seeking guidance on how to address this behavior and aiming to gain a deeper understanding of why it's occurring.
-- main.lua
...
function love.keypressed(keypressed)
Player:jump(keypressed, nil)
end
---
-- player.luq
...
function Player:jump(keypressed, keyreleased)
if keypressed == "space" then
self.jumpBufferTimer = self.jumpBufferTime
end
if (self.coyoteTimer > 0 and self.jumpBufferTimer > 0) then
self.yVel = self.jumpAmount
self.grounded = false
self.coyoteTimer = 0 -- Prevents player from multi-jumping by spamming the jump button
self.jumpBufferTimer = 0
end
if keyreleased == "space" then -- Allows the player to jump less high when the jump button is pressed quickly
self.yVel = self.yVel * 0.5
end
end
...
Input with Jump Buffer
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: Input with Jump Buffer
love.keypressed and love.keyreleased events only trigger once for a given key press and release. Think of them as alarms for when either action happens (press, release), as opposed to them getting continuously checked. The way your code is laid out, Player:jump is called only when these events are triggered, hence why you get the jump when releasing the key. If you want to implement a jump buffer, you'd have to implement the behavior in a way that it continuously checks for the conditions (is the jump key held down, and was it pressed within the jump buffer's allowance?), as opposed to only checking when the events happen.
This could be done by putting the "status" of a key to a table based on the press/release events; effectively you keep a list of keys that have been pressed, and for how long. You could also optionally keep track of when a given key was released. Then, once you've done that, you make your player object check this table whenever you need to, like for this jump buffer situation.
This could be done by putting the "status" of a key to a table based on the press/release events; effectively you keep a list of keys that have been pressed, and for how long. You could also optionally keep track of when a given key was released. Then, once you've done that, you make your player object check this table whenever you need to, like for this jump buffer situation.
Re: Input with Jump Buffer
Try using this instead in your love.update() function:
Code: Select all
if love.keyboard.isDown('up') then
...
end
[code]
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: Input with Jump Buffer
The issue with love.keyboard.isDown is that if your framerate is low, or the game happens to lag, your key strokes may not get recognized when the update functions run (effectively you tap the button in between the update ticks, making love.keyboard.isDown unable to tell what you did). On that front, I prefer using love.keypressed/released for any non-continuous inputs (like tapping the jump button). And once you set up the system with those event callbacks, it's not too hard to just rely on them.
Re: Input with Jump Buffer
That might be, but if we are talking post 2012+ laptops that should not happen, if other e.g. graphics intensive operations are not taking place.
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: Input with Jump Buffer
If you're losing keypresses because of low frame rate, you can't time them either, so in this case I don't think it makes a difference.
Re: Input with Jump Buffer
Thanks all for the input. I was able to refactor and use a more modular input system which resolved the issue
Who is online
Users browsing this forum: Google [Bot] and 4 guests