Corona SDK中的'applyForce'(一个nil值)

我目前正在创作一款类似于黑莓上的直升机游戏的游戏,目标是避开地雷并在计时器计数到0之前存活下来。当这个目标达成后,游戏就进入下一级别,变得更加困难。为了做到这一点,你必须触摸屏幕使宇宙飞船飞得更高(通过 applyForce)或让它下降(通过重力级别),因为飞船是一个动态物体。以下是此代码的代码。

local function flightUp(self,event)
    print("Just before apply force")
    self:applyForce(0,-0.2,self.x,self.y)
    print(applyForce)
    audio.play(jetSound)
end

function touchS(event)
    if event.phase == "began" then
        ship.enterFrame = flightUp
        Runtime:addEventListener("enterFrame", ship)
    end

    if event.phase == "ended" then
        Runtime:removeEventListener("enterFrame", ship)
    end
end

然后,我通过将一些值改为新的 Lua 文件,复制了 Level 1 的代码来创建 Level 2。当我使用几乎相似的代码时,我收到了错误“尝试调用方法'applyForce'(a nil value)”。这使得我的飞船在屏幕上,但无法飞行或通过重力下降。 除了这个错误之外,level2 Lua 没有错误,直到“touchS1”被调用。

local function flightUp1(self,event)
    print("This is the flight up1")
    self:applyForce(0,-0.2,self.x,self.y)
end

function touchS1(event)
    if event.phase == "began" then
        ship.enterFrame = flightUp1
        Runtime:addEventListener("enterFrame", ship)
    end

    if event.phase == "ended" then
        Runtime:removeEventListener("enterFrame", ship)
    end

end

有人帮我一下。

点赞