小编use*_*058的帖子

Lua/LOVE索引问题

每当我用数组做这样的事情时,我都会遇到一个非常恼人的错误.我有代码在love.load()函数中设置数组:

function iceToolsInit()
    objectArray = {} --for object handling
    objectArrayLocation = 0
end
Run Code Online (Sandbox Code Playgroud)

然后是允许创建对象的代码.它基本上抓取了有关所述对象的所有信息并将其插入到数组中.

function createObject(x, y, renderimage) --used in the load function
    --objectArray is set up in the init function
    objectArrayLocation = objectArrayLocation + 1
    objectArray[objectArrayLocation] = {}
    objectArray[objectArrayLocation]["X"] = x
    objectArray[objectArrayLocation]["Y"] = y
    objectArray[objectArrayLocation]["renderimage"] = 
        love.graphics.newImage(renderimage)
end
Run Code Online (Sandbox Code Playgroud)

在此之后,更新函数读取objectArray并相应地呈现图像:

function refreshObjects() --made for the update function
    arrayLength = #objectArray
    arraySearch = 0
    while arraySearch <= arrayLength do
        arraySearch = arraySearch + 1
        renderX = objectArray[arraySearch]["X"]
        renderY = …
Run Code Online (Sandbox Code Playgroud)

arrays indexing lua love2d

4
推荐指数
1
解决办法
168
查看次数

标签 统计

arrays ×1

indexing ×1

love2d ×1

lua ×1