0
最近,我一直在研究一個遊戲項目,並決定學習如何在love2d中從頭開始製作一個gui。我決定使用OOP,其中菜單對象中有菜單對象和按鈕對象。我有一個問題,我只想在菜單處於活動狀態時繪製按鈕。要做到這一點,最簡單的/最好的辦法可能是有來檢查,如果菜單是活動的,並繪製按鈕如果是這樣的菜單對象的功能...檢查父對象中的值
menu = {
-- menu stuff
button = require("path")
active = false,
buttons = {}
}
function menu.newButton()
--create new button object from button table
end
function menu:drawButton()
if self.active then
for k,v in pairs(buttons)
menu.buttons[k]:draw() -- some draw function that sets the size, pos, and color of the button
end
end
end
這讓我想知道,雖然。有沒有辦法從位於按鈕表格中的函數檢查菜單表格中的值?
對不起,我花了幾天的時間回覆。我對metatables還不是很舒服,但現在我已經對亞穩態做了一些更多的瞭解,這很有意義。 – Jacques