1
我對Lua和Love2D完全陌生,可能根本不理解這些概念。 這是一個Love2D教程,我想改變它,所以當我按下「a」時,例如在鍵盤上,對象將交換(從倉鼠到汽車)等等。love2d簡單繪製交換圖片
你能幫我嗎?
-- Tutorial 1: Hamster Ball
-- Add an image to the game and move it around using
-- the arrow keys.
-- compatible with löve 0.6.0 and up
function love.load()
hamster = love.graphics.newImage("hamster.png")
auto = love.graphics.newImage("auto.png")
x = 50
y = 50
speed = 300
end
function love.update(dt)
if love.keyboard.isDown("right") then
x = x + (speed * dt)
end
if love.keyboard.isDown("left") then
x = x - (speed * dt)
end
if love.keyboard.isDown("down") then
y = y + (speed * dt)
end
if love.keyboard.isDown("up") then
y = y - (speed * dt)
end
if love.keyboard.isDown("escape") then
love.event.quit()
end
if love.keyboard.isDown("a") then
love.draw(auto,x,y)
end
end
function love.draw()
love.graphics.draw(hamster, x, y)
end
謝謝Corbin,但它不起作用,我有與本地狀態有關的錯誤。 rror:main.lua:12:嘗試索引upvalue'state'(一個零值) 堆棧回溯: \t main.lua:12:在函數'load'中 \t [string「boot.lua」]:378: in function <[string'boot.lua']:373> \t [C]:in function'xpcall' – molni
哎呦。未經測試的代碼。高興地指出你在正確的方向。 –
謝謝。現在我要弄清楚屏幕邊界,所以圖像不會「掉出」屏幕。 – molni