【问题标题】:3 point object moving is happening all at once3 点物体移动同时发生
【发布时间】:2015-07-23 23:11:22
【问题描述】:

我目前正在制作一个跳跃游戏,其中屏幕左侧有一个物体,位于平台上。一旦对象成功跳跃并降落在右侧的平台上,它会执行以下操作:

1) 右边的平台向左移动

2) 左侧的平台(您刚从该平台跳下)移出屏幕。

3) 一个新的平台应该出现在屏幕的右侧,从而继续循环。

我已经制作了允许对象跳跃并显示碰撞是否成功的功能。我的问题是,我上面提到的 3 件事发生了,但它继续进行并且不会停止让对象进行下一次跳转。这也使对象离开屏幕,因为平台不断向左移动。调试后,我觉得问题出在碰撞发生的地方。这是因为,一旦它接触到平台,碰撞就会继续发生,直到物体离开平台。我想知道你们是否可以帮助我解决这个问题!

这是我的相关代码的一部分:

local onPlatform = false
local gameStarted = false


function playerCollision( self, event )
    if ( event.phase == "began" ) then
        --if hit bottom column, u get points
        if event.target.type == "player" and event.other.type == "bottomColumn" then
            print ("hit column")
            onPlatform = true


        else
        --if hit anything else, gameOver
            --composer.gotoScene( "restart" )

            print ("hit ground")
        end
    end
end


function moveColumns()
        for a = elements.numChildren,1,-1  do

            --speed of columns moving
            --if greater than -100, keep moving it to left
            --puts platform at the right and stops
            if (elements[a].x > display.contentWidth/1.1) then
                elements[a].x = elements[a].x - 12
            end
            --moves platform to left after it successfully lands
            if (onPlatform == true) then
                if (elements[a].x > display.contentWidth/3 and elements[a].x < display.contentWidth/1.11) then
                    elements[a].x = elements[a].x - 12
                end
            end
            --moves left platform to off-screen and deletes after it passes a certain X-axis
            if (onPlatform == true) then
                if(elements[a].x > -100 and elements[a].x < display.contentWidth/2.99) then
                    elements[a].x = elements[a].x - 12

            --adds score if it goes past a certain X-axis at left side
                elseif(elements[a].x < -100) then
                mydata.score = mydata.score + 1
                tb.text = mydata.score
                elements[a].scoreAdded = true

                elements:remove(elements[a])
                elements[a] = nil
                end
            end 
        end
end

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    什么时候调用 moveColumns?您可以从 playerCollision 中调用它并删除 onPlatform 变量吗?可能需要更多代码才能正确提供帮助。

    【讨论】:

      猜你喜欢
      • 2011-11-11
      • 1970-01-01
      • 2015-02-25
      • 2022-06-29
      • 1970-01-01
      • 1970-01-01
      • 2022-06-10
      • 2011-04-06
      • 1970-01-01
      相关资源
      最近更新 更多