Hello again, I'm stuck on forcing the player to move forward while jumping as long as both keys are pressed. Right now if you run forward and hit the jump button it wont jump, unless you stand still.
I can think of ways of doing this but do I really have to create separate controls for if BOTH keys are pressed?
-- player controls
if love.keyboard.isDown('right') then
curranim = anim.runright
player.dir = "right"
player.x = player.x + 100 * dt
elseif love.keyboard.isDown('left') then
curranim = anim.runleft
player.dir = "left"
player.x = player.x - 100 * dt
elseif love.keyboard.isDown('x') and player.dir == "right" then -- jump
starttimer = true
love.audio.play(audiosrc.jump)
curranim = anim.jumpright
jumping = true
elseif love.keyboard.isDown('x') and player.dir == "left" then
starttimer = true
love.audio.play(audiosrc.jump)
curranim = anim.jumpleft
jumping = true
else
curranim = idleanim
end
Might as well ask about how to let the player fall before he can jump again. Right now holding the jump button forces him to stay in the air until it's released. I have a basic timer to force the audio to stop, I could technically use it to set a flag for "inair" or "onground". Unless there is an easier way?
Ryne wrote:Hello again, I'm stuck on forcing the player to move forward while jumping as long as both keys are pressed. Right now if you run forward and hit the jump button it wont jump, unless you stand still.
I can think of ways of doing this but do I really have to create separate controls for if BOTH keys are pressed?
Might as well ask about how to let the player fall before he can jump again. Right now holding the jump button forces him to stay in the air until it's released. I have a basic timer to force the audio to stop, I could technically use it to set a flag for "inair" or "onground". Unless there is an easier way?
-- player controls
if love.keyboard.isDown('right') then
curranim = anim.runright
player.dir = "right"
player.x = player.x + 100 * dt
elseif love.keyboard.isDown('left') then
curranim = anim.runleft
player.dir = "left"
player.x = player.x - 100 * dt
end -- end the first if sequence and start a new one.
if love.keyboard.isDown('x') then -- let's jump!
starttimer = true
love.audio.play(audiosrc.jump)
jumping = true
if player.dir == "right" then
curranim = anim.jumpright
elseif player.dir == "left" then
curranim = anim.jumpleft
end
--[[ instead of that if sequence we could also do something sexy like this:
curranim = anim["jump"..player.dir]
--]]
end
Hi again, Right now my sprite images are 32x32. Though the sprite itself is less than that. I wan't to offset the hit-box (or bounding box) a little bit. Would it be practical to just give the hit-box itself it's own hitx and hity, or is there an easier way of pulling that off? Right now I'm using this code.
Ryne wrote:Hi again, Right now my sprite images are 32x32. Though the sprite itself is less than that. I wan't to offset the hit-box (or bounding box) a little bit. Would it be practical to just give the hit-box itself it's own hitx and hity, or is there an easier way of pulling that off?
It depends. What do you mean by offset the hitbox? Are all the sprites of different actual sizes or are they the same?
Ryne wrote:Hi again, Right now my sprite images are 32x32. Though the sprite itself is less than that. I wan't to offset the hit-box (or bounding box) a little bit. Would it be practical to just give the hit-box itself it's own hitx and hity, or is there an easier way of pulling that off?
It depends. What do you mean by offset the hitbox? Are all the sprites of different actual sizes or are they the same?
The sprites are IMAGES are 32x32, but the little sprite/character is actually smaller than that, though if I change the w/h of the hitbox it still goes by the IMAGE x/y. So the hitbox is drawn from the top left corner of the image. You know?
Robin wrote:Oh, well than that is the right approach.
lol... Consider the image itself like "canvas size", its 32x32. The character that's being drawn on that canvas is only like 20x25 or something. You know what.. I'm just going to upload an image. Consider the "RED" the hitbox.
Hitbox that's the full size of the image(32x32):
Smaller hitbox:
See how the hitbox is then drawn to the top left, I want it around the character.
Ryne wrote:Hi again, Right now my sprite images are 32x32. Though the sprite itself is less than that. I wan't to offset the hit-box (or bounding box) a little bit. Would it be practical to just give the hit-box itself it's own hitx and hity, or is there an easier way of pulling that off?
It depends. What do you mean by offset the hitbox? Are all the sprites of different actual sizes or are they the same?
The sprites are IMAGES are 32x32, but the little sprite/character is actually smaller than that, though if I change the w/h of the hitbox it still goes by the IMAGE x/y. So the hitbox is drawn from the top left corner of the image. You know?
love.graphics.draw has offset x and offset Y parameters, I would use those for clarity.
local offsetX = 6 -- 6px on each side
local offsetX = 7 -- 7px above
love.graphics.draw(self.image, self.x, self.y, 0, 1, 1, offsetX, offsetY)
Just a note: slightly off hitboxes end up being an enormous pain in my experience. I regret using them in my game, and you might end up in the same boat.
Regarding the sound: It hurts when I see this, please stop reloading sounds using newSource with static as 2nd arg, if you want multiple static sounds do it in a way that only requires 1 decoding operation, not everytime you play. The correct way for static sounds is creating SoundData, this contains the decoded sound, passing it to newSource will make it static, but not decode again.
Regarding hitboxes:
If you can, place the content of your images (before padding) top-left, that way you don't have to change position manually, and you just ignore the bit on the bottom and right.