如何在 Corona SDK 中修复一个函数中的错误?

我有一个名为 CreateGround 的函数,它会在玩家下面创建一个表面,如果已经存在于地面上,则沿着 x 轴移动到平台的宽度。 但出于某种原因它对我而言不起作用,我想要理解并修正这个问题。

这是我的代码:

local function createGround ()
  local ground = display.newImageRect( mainGroup, objectSheet, 3, 390, 265 )
  ground.x = 195
  ground.y = yc+(yc*0.9)
  physics.addBody( ground, "static" )
  table.insert( groundTable, ground )
end

local function groundUpdater()
  createGround()

  for i = #groundTable, 1, -1 do
    local thisGround = groundTable[i]
    print(thisGround)
    local otherGround = groundTable[i-1]
    if (thisGround.x == otherGround.x) then
      otherGround.x = otherGround.x + 390
    end
    if (thisGround.x >= width+500 or thisGround.x <= -500) then
      display.remove( thisGround )
      table.remove( groundTable, thisGround)
    end
  end
end

错误屏幕: enter image description here

点赞