I need help. ;(

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Juryo
Prole
Posts: 5
Joined: Fri Aug 24, 2012 3:14 pm

I need help. ;(

Post by Juryo »

I am making a game called "Insomnia". It's a 2d horror game. I'm having a bit trouble with player movement, I have the movement part nailed down but when I move the opposite direction that the character is facing, it goes in that direction, but when I left go of "A, left movement" the characters texture will go back to the right, could anyone tell me how to fix this? I have two separate textures for both the character facing left & right.

Example:

Pic #1: Walking whilst holding "D" Pic #2: Walking whilst holding "A" Pic #3: When I stop holding "A"
ImageImageImage

My current code:
Image

I hope I made this fully understandable.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: I need help. ;(

Post by Nixola »

You have to check what's the last key held down by using love.keyreleased), and use that to decide where the player's facing
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: I need help. ;(

Post by Kadoba »

Like Nixola said, you need to figure out what the last key held down is. Since you're only using two directions you can do it this way:

Code: Select all

local moveKey
local playerImages = {}
playerImages["idle"] = love.graphics.newImage("textures/character_idle.png")
playerImages["left"] = love.graphics.newImage("textures/character_left.png")
playerImages["right"] = love.graphics.newImage("textures/character_right.png")


function love.keypressed(key)
  if key == "left" or key == "right" then moveKey = key end
end

function love.keyreleased(key)
   if key == "left" or key == "right" then moveKey = nil end
   if key == "left" and love.keyboard.isDown("right") then moveKey = "right" end
   if key == "right" and love.keyboard.isDown("left") then moveKey = "left" end
end

function player_draw()
   love.graphics.setColor(255,255,255)
   love.graphics.draw(playerImages[moveKey] or playerImages["idle"], player.x, player.y)
end
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: I need help. ;(

Post by Lafolie »

Wouldn't it make more sense to do that in keypressed rather than released?
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: I need help. ;(

Post by Nixola »

No, because if you press and hold right, then press and hold left, then release lef love.keypressed can't know it and it will continue facing left
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Juryo
Prole
Posts: 5
Joined: Fri Aug 24, 2012 3:14 pm

Re: I need help. ;(

Post by Juryo »

I'm sorry to say, but it did the same thing as before. ;(
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: I need help. ;(

Post by Nixola »

Did you use that variable to draw the correct animation?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Juryo
Prole
Posts: 5
Joined: Fri Aug 24, 2012 3:14 pm

Re: I need help. ;(

Post by Juryo »

Yes, I did.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: I need help. ;(

Post by kikito »

Please post a .love file showing your problem.
When I write def I mean function.
Juryo
Prole
Posts: 5
Joined: Fri Aug 24, 2012 3:14 pm

Re: I need help. ;(

Post by Juryo »

I don't understand why I would need to implement one, but here is the .zip. Just open it with love.exe ^^
Attachments
Insomnia BUG ONLY.zip
(1.16 MiB) Downloaded 137 times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest