0
我不知道我在做什麼錯...我得到的錯誤在player.draw()函數。它所談論的壞論點是在love.graphics.rectangle()方法中。這就是說v.x是一個不好的論點。但它應該工作。 v.x和v.y都應該可以工作。因爲它訪問表或數組內的元素的權利?有人能告訴我我做錯了什麼,以及如何解決這個問題?非常感謝!這裏是我的代碼:love2D錯誤:'矩形'的錯誤參數#2(數字預期,得到零)
require "scripts.player"
width = love.graphics.getWidth()
block = {}
block.width = 60
block.height = 10
block.speed = 150
block.timer = 0
block.timerLim = math.random(1,2)
block.spawnX = math.random(0, width - player.width)
function block.spawn(x,y)
table.insert(block, {x = x, y = y})
end
function block.move(dt)
for i,v in ipairs(block) do
v.y = v.y + block.speed * dt
end
end
function block.draw()
for i,v in ipairs(block) do
love.graphics.setColor(255,0,255)
love.graphics.rectangle("fill", v.x, v.y, block.width block.height)
end
end
function block.spawnHandler(dt)
block.timer = block.timer + dt
if block.timer > block.timerLim then
block.spawn(spawnX, -10)
block.timer = 0
block.timerLim = math.random(1,2)
block.spawnX = math.random(0, width - block.width)
end
end
-- Parent Functions --
function DRAW_BLOCK()
block.draw()
end
function UPDATE_BLOCK(dt)
block.move(dt)
block.spawnHandler(dt)
end
哇,它的工作!非常感謝! –