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

时间:2018-04-24 07:00:13

标签: function lua corona

我有一个名为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

0 个答案:

没有答案