我已經做了大量的關於點和點擊遊戲的Lua和日冕的invetory系統的研究。 我遇到過這個例子,我正在做類似的事情,但我需要一個動態庫存系統。 我的意思是如果我有4個插槽,並且它們都已滿,第五個對象將轉到下一個插槽,所以會有一個向右的箭頭,以便我可以點擊;然後轉到下一頁。 並設想有5項,我有4個插槽,第五個插槽將在下一頁。 我使用第三個項目,第三個插槽然後是空的,所以我希望第四個和第五個項目自動回到第三個和第四個插槽。 我很難搞清楚這一點。 感謝您的提前。如何爲點擊遊戲設計「動態庫存系統」?
local myInventoryBag={}
local maxItems = 10 -- change this to how many you want
myInventoryBag[5]=3 -- Hammer for instance
myInventoryBag[4]=7 -- A metal Pipe for instance
local function getImageForItem(thisItem)
local itemNumber = tonumber(thisItem)
local theImage=""
if itemNumber==3 then
theImage="hammer.png"
elseif itemNumber == 7 then
theImage="metalpipe.png"
elseif ... -- for other options
...
else
return nil
end
local image = display.newImage(theImage)
return image
end
local function displayItems()
local i
for i=1,#myInventoryBag do
local x = 0 -- calculate based on the i
local y = 0 -- calculate based on the i
local image = getImageForItem(myInventoryBag[i])
if image==nil then return end
image.setReferencePoint(display.TopLeftReferencePoint)
image.x = x
image.y = y
end
end
感謝您的幫助,環顧四周,玩了很多後,我覺得有很多方法可以創建一個動態庫存系統。因爲我已經進入了7個月的編程,並仍在學習;有時我傾向於認爲,只能有一種方法或解決方案。 –