在corona中清理桌子

我遇到了在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()函数。

点赞
用户1682268
用户1682268
有类似于这样的问题在 Corona 中,就像我在之前的回答中说的一样,如果你想重新创建 storyboard 中的所有数据和值,那么必须在跳转到另一个场景后移除你的场景,或者你可以在 scene:Enterscene() 函数中重置你的值,这样如果你返回到之前的场景,它将重置这些值。

也许这些链接可以帮助你:

- 用于移除和清除场景的链接
  [http://www.coronalabs.com/blog/2012/07/31/storyboard-scene-purging-vs-removal/](http://www.coronalabs.com/blog/2012/07/31/storyboard-scene-purging-vs-removal/)
- 用于 storyboard 的链接
  [http://www.coronalabs.com/blog/2011/11/14/introducing-the-storyboard-api/](http://www.coronalabs.com/blog/2011/11/14/introducing-the-storyboard-api/)
2013-07-02 16:16:33