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/1/angularjs/25.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 电晕与随机物理景观_Lua_Coronasdk_Physics - Fatal编程技术网

Lua 电晕与随机物理景观

Lua 电晕与随机物理景观,lua,coronasdk,physics,Lua,Coronasdk,Physics,我正在制作一个游戏,使用一个角色沿着由随机挑选的不同“部分”组成的轨道驾驶。它使用物理,大多数物体都有许多顶点,并且是用物理编辑器制作的。我的实现不是很好,因为每次需要新的部分时,我都会重新创建每个部分。这会导致帧速率跳过,因为它必须在“时间关键”的游戏中创建这些大型物理实体。每个部分都有2000像素长,到目前为止我有7个。有人能告诉我一个更好的方法来实现这一点吗?谢谢 以下是我用于拾取和创建随机部分的函数: local secNeeded=false local secNum=2 l

我正在制作一个游戏,使用一个角色沿着由随机挑选的不同“部分”组成的轨道驾驶。它使用物理,大多数物体都有许多顶点,并且是用物理编辑器制作的。我的实现不是很好,因为每次需要新的部分时,我都会重新创建每个部分。这会导致帧速率跳过,因为它必须在“时间关键”的游戏中创建这些大型物理实体。每个部分都有2000像素长,到目前为止我有7个。有人能告诉我一个更好的方法来实现这一点吗?谢谢

以下是我用于拾取和创建随机部分的函数:

 local secNeeded=false

 local secNum=2

 local totallength=-800

 local function newSec()
 if secNeeded==true then
 local levNum=math.random( 1, 7 )
if secNum==1 then
        display.remove( group1 )
        group1 = nil
        group1=display.newGroup()
        game:insert(group1)
end
if secNum==2 then
        display.remove( group2 )
        group2 = nil
        group2=display.newGroup()
        game:insert(group2)
end
if secNum==3 then
        display.remove( group3 )
        group3 = nil
        group3=display.newGroup()
        game:insert(group3)
end

    if levNum == 1 then
        createRamp()
    end

    if levNum == 2 then
        createdoubleRamp()
    end

    if levNum == 3 then
        createHill()
    end

    if levNum == 4 then
        createRampHill()
    end
    if levNum == 5 then
        createUpHill()
    end
    if levNum == 6 then
        createDownHill()
    end
    if levNum == 7 then
        createTunnel()
    end
 end
 secNum=secNum+1
if secNum==4 then
    secNum=1
end 

 end


 local function wheelMid(event)
 --print(totallength)
 --print(wheel.x)
 if wheel.x>totallength then
 secNeeded=true
 newSec()
 end
 end

 Runtime:addEventListener( "enterFrame", wheelMid)
以及创建函数的示例

        function createHill()

            local mega=display.newGroup()
            local guide = display.newRect(0,0, 2000, 50)
            guide.x=totallength+2000
            guide.y=totalheight
            guide.alpha=0
            mega:insert(guide)

            local ground = display.newImageRect("ground.png", 2000, 600)
            ground.x=guide.x
            ground.y=guide.y+200
            mega:insert(ground)
            physics.addBody(ground, "static", { friction=0.5 }) 

            local hill= display.newImageRect("hill2.png", 1400, 900)
            hill.x=guide.x+300
            hill.y=guide.y-534
            mega:insert(hill)
            physics.addBody( hill, "static", physicsData:get("hill2") )

                if secNum==1 then
            group1:insert(mega)
            end
            if secNum==2 then
            group2:insert(mega)
            end
            if secNum==3 then
            group3:insert(mega)
            end

            totallength=guide.x
            secNeeded=false

    end
这些组是相同的,因此一次有3个部分。
有什么更好的方法来实现这一点,消除帧跳过?如果有人能帮助我或给我指出正确的方向,我将非常感激

通过故事板预加载场景。loadScene可能是您正在寻找的内容。

我的建议是在游戏启动时(或在实际开始跑步之前)加载7种不同类型的棋子,然后通过将alpha设置为0来隐藏它们,当游戏真正开始时,你总是重复使用相同的7件,而不是重新制作它们。。。例如,当您随机选择一个时,您可以从一组7个片段中进行选择,将alpha设置为1,并将其x/y位置移动到精确的点


这样,您就不会每次都重新创建它,而且会更快。

谢谢。如果我希望同一个片段在一行中出现两次,该怎么办?2个选项:1-您可以预先创建2x7片段,而不是:)或者甚至3x7,如果您可以在一行中出现3次相同片段。这样,同一件作品可以在一行中选择2到3次:)2-您确保同一件作品不能在一行中选择两次:)Sam答案对您无效吗?重复的