【发布时间】:2016-12-27 05:57:20
【问题描述】:
今天,我正忙着为我想开始在 LOVE2D 中制作的游戏制作一个 gui 类。我决定尝试使用 OOP,以便将来更轻松地创建新菜单。 OOP 工作得很好,直到我尝试将它放入它自己的模块中,它给了我上面的错误。我已经根据类似的代码对我的代码进行了两次和三次检查,但我找不到问题所在。我也查了一下,有类似的线程,但没有什么能帮助我解决问题。这是相关代码...
来自main.lua
local gui = {
x = 0, y = 0,
width = 0, height = 0,
popupSpeed = 300,
active = false,
color = {red = 0, blue = 0, green = 0, alpha = 0},
menuType = "",
--buttons = require "Game/buttons"
}
从 gui.lua...
local newGUI = require "Game/gui"
local menus = {
playerInv = newGUI.new()
}
function love.load()
menus.playerInv:createDropDown("right" , _, 30, 100, love.graphics.getHeight() - 60, 50, 128, 50, 255)
end
function gui.new()
newMenu = {}
for k, v in pairs(gui) do
newMenu[k] = v
end
return newMenu
end
function gui:createDropDown(direction, x, y, width, height, red, blue, green, alpha)
self.red = red
self.blue = blue
self.green = green
self.alpha = alpha
if direction == "right" then
self.x = love.graphics.getWidth() - width
self.y = y
self.width = width
self.height = height
self.menuType = "rightDropDown"
elseif direction == "left" then
self.x = 0
self.y = y
self.widthMax = width
self.height = height
self.menuType = "leftDropDown"
elseif direction == "down" then
self.x = x
self.y = y
self.width = width
self.heightMax = height
self.menuType = "regDropDown"
end
end
function gui:drawGui()
if self.active == true then
love.graphics.setColor(self.red, self.blue, self.green, self.alpha)
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height, 10, 10, 6)
end
end
【问题讨论】: