Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.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/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
Android 为Physical.setGravity指定不同的值 --*************************************************** --drawButtons()--> --*************************************************** 本地飞行平面=功能(事件) 如果event.phase==“开始”且gameIsActive==真,则 打印(“开始”) 物理学.重力(0,-10) elseif event.phase==“结束”,gameIsActive==true 打印(“结束”) 物理学.重力设置(0,7) 入站=真 elseif event.phase==“moved”和gameIsActive==true然后 --无所事事 终止 终止 --*************************************************** --keepPlaneInBound()--> --*************************************************** 本地keepPlaneInBound=函数() --打印(“检查”) 如果paperPlane.y display.contentHeight-paperPlane.height-scale.height和gameIsActive==true,则 paperPlane.y=display.contentHeight-paperPlane.height-scale.height 终止 终止_Android_Lua_Coronasdk_Game Engine_Physics - Fatal编程技术网

Android 为Physical.setGravity指定不同的值 --*************************************************** --drawButtons()--> --*************************************************** 本地飞行平面=功能(事件) 如果event.phase==“开始”且gameIsActive==真,则 打印(“开始”) 物理学.重力(0,-10) elseif event.phase==“结束”,gameIsActive==true 打印(“结束”) 物理学.重力设置(0,7) 入站=真 elseif event.phase==“moved”和gameIsActive==true然后 --无所事事 终止 终止 --*************************************************** --keepPlaneInBound()--> --*************************************************** 本地keepPlaneInBound=函数() --打印(“检查”) 如果paperPlane.y display.contentHeight-paperPlane.height-scale.height和gameIsActive==true,则 paperPlane.y=display.contentHeight-paperPlane.height-scale.height 终止 终止

Android 为Physical.setGravity指定不同的值 --*************************************************** --drawButtons()--> --*************************************************** 本地飞行平面=功能(事件) 如果event.phase==“开始”且gameIsActive==真,则 打印(“开始”) 物理学.重力(0,-10) elseif event.phase==“结束”,gameIsActive==true 打印(“结束”) 物理学.重力设置(0,7) 入站=真 elseif event.phase==“moved”和gameIsActive==true然后 --无所事事 终止 终止 --*************************************************** --keepPlaneInBound()--> --*************************************************** 本地keepPlaneInBound=函数() --打印(“检查”) 如果paperPlane.y display.contentHeight-paperPlane.height-scale.height和gameIsActive==true,则 paperPlane.y=display.contentHeight-paperPlane.height-scale.height 终止 终止,android,lua,coronasdk,game-engine,physics,Android,Lua,Coronasdk,Game Engine,Physics,功能flyPlane设置在“touch”eventlistner上,KeepPlaneInBond设置为“enterframe”eventlistner。我想要达到的是,当平面超过上限时。它以前的physcis.setGravity值将被完全删除,并且在用户抬起手指时(event=“end”)将为其分配新值。 奇怪的是,它不接受新的physics.setGravity()值。如果我使用physics.pause()并为其指定新的重力值。在physics.start上,它首先完成上一个设置重力值的

功能flyPlane设置在“touch”eventlistner上,KeepPlaneInBond设置为“enterframe”eventlistner。我想要达到的是,当平面超过上限时。它以前的physcis.setGravity值将被完全删除,并且在用户抬起手指时(event=“end”)将为其分配新值。 奇怪的是,它不接受新的physics.setGravity()值。如果我使用physics.pause()并为其指定新的重力值。在physics.start上,它首先完成上一个设置重力值的部分,然后再次向上移动..:/

您不应该在“enterFrame”中使用“flyPlane”作为回调。你应该有这样的东西:

--***************************************************

-- drawButtons() --> 

--***************************************************

local flyPlane = function(event)

    if event.phase == "began" and gameIsActive == true then
        print("began")
        physics.setGravity( 0, -10 )
    elseif event.phase == "ended" and gameIsActive == true then
        print("ended")
        physics.setGravity( 0, 7 )
        inBound = true
    elseif event.phase == "moved" and gameIsActive == true then
        -- do nothing
    end

end

--***************************************************

-- keepPlaneInBound() --> 

--***************************************************

local keepPlaneInBound = function()
    -- print("checking")
    if paperPlane.y <= paperPlane.height + 10 and gameIsActive == true and inBound == true then
        inBound = false
        paperPlane.y = paperPlane.height + 12
    end

    if paperPlane.y > display.contentHeight - paperPlane.height - scale.height and gameIsActive == true then
        paperPlane.y = display.contentHeight - paperPlane.height - scale.height
    end

end

这就是你所需要的。(假设您的游戏逻辑正确)

各位。我得到了我想要的。为了给物理体指定一个新的重力值,完全移除施加在物理体上的力的技术是简单地将其体型更改为不同的体型,然后再次将所需的体型指定回对象。这样,之前重力值对物理对象的影响就完全消除了。这就是我所做的。这确实对我有用

local function flyPlane(event) 
   your_code()
end

local function keepPlaneInBound(event)
   your_code()
end

paperPlane:addEventListener("touch", flyPlane)
Runtime:addEventListener("enterFrame", keepPlaneInBound)
--drawButtons()-->
--***************************************************
本地飞行平面=功能(事件)
如果event.phase==“开始”且gameIsActive==真,则
打印(“开始”)
--paperPlane.bodyType=“动态”
物理学.重力(0,-10)
--物理开始
elseif event.phase==“结束”,gameIsActive==true
打印(“结束”)
--paperPlane.bodyType=“动态”
物理学.重力设置(0,7)
--物理开始
elseif event.phase==“moved”和gameIsActive==true然后
终止
终止
--***************************************************
--keepPlaneInBound()-->
--***************************************************
本地keepPlaneInBound=函数()
--打印(“检查”)
如果paperPlane.y display.contentHeight-paperPlane.height-scale.height和gameIsActive==true,则
打印(“未装订+y:”,纸张平面。主体类型)
物理暂停()
paperPlane.bodyType=“静态”
paperPlane.y=display.contentHeight-paperPlane.height-scale.height-1
其他的
打印(“装订:”,paperPlane.bodyType)
paperPlane.bodyType=“动态”
物理开始
终止
终止

重力代码基本上没有问题,无法确定边界检查,因为在
keepPlaneInBound
中似乎有一个额外的“end”会导致语法错误。因此,请纠正这一点,并编辑您的问题,以显示您注册事件回调的代码,这可能就是错误所在。@scholli。嗨,谢谢你帮我。你所说的“结束”是错误地添加到这里的。我已经识别了密码。现在,代码与我的记事本++中的代码完全相同。好的,但正如我提到的,我看不出你的代码有任何错误,我甚至尝试在测试应用程序中更改重力,效果很好,所以问题在于你没有显示的代码。请显示addEventListener调用,以及用于调用这两个函数的任何其他代码。“功能flyPlane设置为“touch”“enterframe”eventlistner”没有意义,需要查看code.sore,@Schollii。我同意你的看法,我在描述这个问题时犯了一些严重的错误。现在已经解决了。我已经发布了我为摆脱它所做的事情。无论如何,谢谢。:)嗨,亚当,谢谢你的帮助。是的,这让我走到了接近解决方案的地方。但主要问题仍然存在。当玩家从屏幕上抬起手指时,我想指定给paperPlane对象的重力值。该对象只是保持自身与先前指定的重力值(在“开始”事件时指定)一致。唯一可能的原因是GameiActive布尔值被计算为false。-顺便说一句,你不必做“if boolean==true then”,你只需说“if boolean then”就行了,因为setGravity会立即(即一旦事件处理程序返回)在所有物体上工作,而不会暂停物理过程(我已经验证)。为了让新引力生效,你必须改变每一种物理身体类型(根本)是没有意义的。这是一次黑客攻击,出了点问题。
-- drawButtons() --> 

--***************************************************

local flyPlane = function(event)

    if event.phase == "began" and gameIsActive == true then
        print("began")
        -- paperPlane.bodyType = "dynamic"
        physics.setGravity( 0, -10 )
        -- physics.start()
    elseif event.phase == "ended" and gameIsActive == true then
        print("ended")
        -- paperPlane.bodyType = "dynamic"
        physics.setGravity( 0, 7 )
        -- physics.start()
    elseif event.phase == "moved" and gameIsActive == true then
    end

end

--***************************************************

-- keepPlaneInBound() --> 

--***************************************************

local keepPlaneInBound = function()
    -- print("checking")
    if paperPlane.y <= paperPlane.height + 10 and gameIsActive == true then
        print("Out of Bound -y:   ", paperPlane.bodyType)
        physics.pause()
        paperPlane.bodyType = "static"
        paperPlane.y = paperPlane.height + 11
    elseif paperPlane.y > display.contentHeight - paperPlane.height - scale.height and gameIsActive == true then
        print("Out of Bound +y:   ", paperPlane.bodyType)
        physics.pause()
        paperPlane.bodyType = "static"
        paperPlane.y = display.contentHeight - paperPlane.height - scale.height - 1
    else 
        print("In Bound:    ", paperPlane.bodyType)
        paperPlane.bodyType = "dynamic"
        physics.start()
    end

end