我在清除LUA表中的数据时遇到了问题。我使用场景插件,只要玩家前进到下一个场景,我就想重置表格中的数据。
我使用这个函数来创建游戏元素:
local function createGrips()
local originX = 0
local originY = height -75
for i=0,numberGrips do
r = math.random(3)
local x = originX + math.random(width)
local y = originY - math.random(2*height)
grip[i] = display.newRect(allElements, x, y, gripSize[r].w, gripSize[r].h)
grip[i].status = "active"
grip[i].size = gripSize[r].s
if (r == 1) then
grip[i]:setFillColor(51,255,0)
elseif (r == 2) then
grip[i]:setFillColor(255,51,51)
elseif (r == 3) then
grip[i]:setFillColor(51,51,255)
end
end
end
createGrips()当我移动到下一个场景时,我尝试了所有这些选项来清理表格:
grip={}或者是这个
for i=#grip,0, -1 do
table.remove(grip,i)
end但结果保持不变。元素一直停留在屏幕上。唯一起作用的就是grip=nil。但是当我返回到函数createGrips()时,这就产生了一个错误。
重置所有数据的最佳方法是什么?我对所有字符都使用了removeSelf()函数。
发布于 2013-07-03 00:16:33
在corona中有类似的问题,就像我在前面的回答中所说的,如果你想在你的故事板中重新创建所有的数据和值,你必须在转到另一个场景后移除你的场景,或者你可以在场景中重置你的值:Enterscene()函数,所以如果你回到上一个场景,它将重置这些值
也许这个链接可以帮助你
为storyboard http://www.coronalabs.com/blog/2011/11/14/introducing-the-storyboard-api/删除和清除scene http://www.coronalabs.com/blog/2012/07/31/storyboard-scene-purging-vs-removal/
https://stackoverflow.com/questions/17429095
复制相似问题