0
我在跟隨tutorial教我如何製作平臺遊戲。在第二個教程中,我們開始製作渲染器。每當我運行代碼和測試渲染,我得到這個錯誤Love2D渲染器錯誤
Error: main.lua:24: attempt to index global 'renderer' (a nil value)
我沒有知道如何解決它,所以這裏是我的代碼。
renderer.lua
local Renderer = {}
local num_of_layers = 5
local insert = table.insert
local remove = table.remove
function Renderer:create()
local renderer = {}
--
renderer.drawers = {}
for i = 0,num_of_layers do
renderer.drawers[i] = {}
end
--
function renderer:addRenderer(obj, Layer)
local l = layer or 0
insert(self.drawers[l], obj)
end
--
function renderer:draw()
for layer = 0,#self.drawers do
for draw = 0,#self.drawers[layer] do
local obj = self.drawers[layer][draw]
if obj ~= nil then
obj:draw()
end
end
end
end
return renderer
end
--
return Renderer
這裏是main.lua
local Renderer = require("libs/renderer")
Renderer = Renderer:create()
function love.load()
love.graphics.setBackgroundColor(255, 255, 255)
--Loading Classes
player_load()
--Loading Classes
end
--
function love.update(dt)
end
--
function love.draw()
renderer:draw()
end
謝謝大家誰是閱讀!
OMG!我不相信我沒有注意到!非常感謝! –