Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 科罗纳sdk&x27;applyForce';(零值)_Lua - Fatal编程技术网

Lua 科罗纳sdk&x27;applyForce';(零值)

Lua 科罗纳sdk&x27;applyForce';(零值),lua,Lua,我目前正在制作一个类似于blackberry上直升机游戏的游戏,游戏的目标是避开地雷并生存到计时器计数为0,当这一点实现时,游戏将进入下一个级别,在那里它将变得更加困难。要做到这一点,你必须触摸屏幕,使飞船飞得更高(通过applyForce)或降低(通过重力),因为飞船是一个动态物体。代码如下所示 local function flightUp(self,event) print("Just before apply force") self:applyForce(0,-0.2,

我目前正在制作一个类似于blackberry上直升机游戏的游戏,游戏的目标是避开地雷并生存到计时器计数为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
然后,我通过复制level 1的代码并将一些值更改为新的lua文件来创建level 2。当使用几乎相似的代码时,我得到一个错误“尝试调用方法‘applyForce’(一个零值)”,使我的宇宙飞船出现在屏幕上,但无法在重力作用下飞行或降落。 除此错误外,在调用“Touch1”之前,level2 lua没有错误

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

请有人帮帮我吧

也许,在
运行时注册:addEventListener
可以使您的侦听器功能适用于所有对象(而不仅仅是船舶)。当为另一个类(没有
applyForce
method)的对象调用侦听器时,会出现错误。