今日、私は作ってみたいゲームのGUIクラスを作ろうとしていましたLOVE2Dで私は、OOPを使って将来的に新しいメニューを作成しやすくすることに決めました。 OOPは私が試してみるまでそれを自分のモジュールに入れて、上のエラーが出るまでうまくいっています。私は二重と三重を似たようなコードに対して私のコードをチェックして、私は問題を見つけることができません。私もそれを見て、同様のスレッドが、私の問題に役立つものは何もありません。ここでは、関連するコード... main.luaOOP GUIエラー:main.lua:4:ローカル(ブール値)のインデックスを作成しようとしています...モジュールの問題
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
ありがとうございます!私はこれを読む前に少し考え出しましたが、それでも役立ちます。また、良いチュートリアルやスレッド、またはluaでGUIを構築する方法についてのようなものがありますか? – Jacques
Love2Dには、サンプルコードを読んで、実行して修正するサンプルプロジェクトが必要です。 https://love2d.org/wiki/examples.love –