【发布时间】:2021-04-26 09:05:26
【问题描述】:
如何在函数 love.graphic.rettangle 中使用 Table coin 而不使其全局化?我在 love.update() 函数中声明了表(我不知道是否有任何变化)
if math.random() < 0.01 then --math.rand restituisce numeri da 0 a 1 (la usiamo come probabilità)
local coin = {}
coin.h = 80
coin.w = 80
coin.x = math.random(0, 800 - coin.w)
coin.y = math.random(0, 800 - coin.h)
table.insert(coins, coin)-- inseriamo nella table coins il table coin appena creato
end
end
function love.draw()
--[[love.graphics.setBackgroundColor( 255, 150, 150)
love.graphics.setColor(255, 0, 0)]]
love.graphics.setColor(255, 0, 0)
love.graphics.rectangle("fill", player.x, player.y, player.w, player.h)
love.graphics.setColor(255, 255, 0)
for i=1, #coins, 1 do
love.graphics.rectangle("fill", coin.x, coin.y, coin.w, coin.w, coin.h)
end
end
【问题讨论】:
-
你写的是
coin而不是coins[i] -
如果您发布带有行号的错误消息,请从头发布代码或添加注释告诉大家哪一行是第50行。这样我们就不必通读所有你的代码。这就是错误消息带有行号的原因。这样您就知道在哪里寻找错误原因。