For some reason the code is not responding when i got the code if love.keyboard.isDown("s") Maybe i am using the functions just wrong but its still weird.
I tried using the Menu() function in love.keypressed and in love.update. Still no response.
Here is the full code:
main.lua
function love.load()
require "menu"
select = love.graphics.newImage("select.png")
Menu()
end
function love.draw()
Menu()
end
function love.keypressed(key)
Menu()
end
function love.update()
Menu()
end
menu.lua
function Menu()
sly = 300
love.graphics.draw(select,sly,300)
if key == "w" then
sly = sly + 50
end
if love.keyboard.isDown("s") then
sly = sly - 50
end
end
Not sure what exactly you are trying to do here, but in your
Menu()function you are resetting theslyvariable every time you call it, and then modifyingslyafter you have already drawn the image. This results in nothing happening.If you change it so that
slyis initialized outsideMenu(), it at least moves the image when you press the ‘s’ key. Also, if you wanted ‘s’ to move it one way and ‘w’ to move it the other way, maybe the code should be like this:Or you could pass the
keyvariable intoMenu()when you call it fromlove.keypressedand not use thekeyboard.isDownfunction.Again, I’m not sure what you are really trying to do here, but it looks to me like the code is working fine, you may just have a logic error.