Composer触发场景在一个gotoScene(“...”)命令上多次显示

时间:2014-12-08 11:14:36

标签: ipad lua corona

我有一个(Corona SDK)项目来加载一系列场景(作曲家),我的3个场景中似乎加载了newVideo对象,场景:show被多次激发,我无法理解这是为什么。

调用代码如下所示:

local btn2 = self:getObjectByTag("button2");
    local function btn2_click(e) 
    if(e.phase == "ended") then
        composer.gotoScene("video_paulprice");
    end
end
btn2:addEventListener("touch", btn2_click);

作曲家场景节目方法如下所示:

function scene:show( e )
    local sceneGroup = self.view
    local phase = e.phase

    local halfscreenwidth=display.contentWidth/2;
    local halfscreenheight=display.contentHeight/2

    local bg = self:getObjectByTag("backgroundBox");
    bg.x= display.contentWidth/2;
    bg.y= display.contentHeight/2;
    bg.xScale=0.5;
    bg.yScale=0.5;

    print("CM PHASE: " .. e.phase)

    if (phase == "did") then
    video = native.newVideo( display.contentCenterX+1, display.contentCenterY-40, 535, 390 );
    local function videoListener( event )
        print( "Event phase: " .. event.phase );
    end
    video:load( "videos/video_1.mp4", system.ResourceDirectory );
    video:addEventListener( "video", videoListener );
    video:play()

    end 

    local btn1 = self:getObjectByTag("button1");
    local function btn1_click(e) 
        display.remove(video)
        composer.gotoScene("scene3");
    end
    btn1:addEventListener("tap", btn1_click);


    local btn2 = self:getObjectByTag("button2");
    local function btn2_click(e) 
        video:removeSelf()
        composer.gotoScene("scene4");
    end
    btn2:addEventListener("tap", btn2_click);

end

我的终端,调试器输出如下所示:

2014-12-08 10:37:29.756 Corona Simulator[4392:175603] CM PHASE: will
2014-12-08 10:37:29.757 Corona Simulator[4392:175603] CM PHASE: did
2014-12-08 10:37:29.852 Corona Simulator[4392:175603] CM PHASE: will
2014-12-08 10:37:29.852 Corona Simulator[4392:175603] CM PHASE: will
2014-12-08 10:37:29.852 Corona Simulator[4392:175603] CM PHASE: will
2014-12-08 10:37:29.852 Corona Simulator[4392:175603] CM PHASE: will
2014-12-08 10:37:29.852 Corona Simulator[4392:175603] CM PHASE: will
2014-12-08 10:37:29.853 Corona Simulator[4392:175603] CM PHASE: will
2014-12-08 10:37:29.853 Corona Simulator[4392:175603] CM PHASE: will
2014-12-08 10:37:29.885 Corona Simulator[4392:175603] CM PHASE: did
2014-12-08 10:37:29.885 Corona Simulator[4392:175603] CM PHASE: did
2014-12-08 10:37:29.885 Corona Simulator[4392:175603] CM PHASE: did
2014-12-08 10:37:29.885 Corona Simulator[4392:175603] CM PHASE: did
2014-12-08 10:37:29.885 Corona Simulator[4392:175603] CM PHASE: did
2014-12-08 10:37:29.886 Corona Simulator[4392:175603] CM PHASE: did
2014-12-08 10:37:29.886 Corona Simulator[4392:175603] CM PHASE: did
Other scenes in my project the show method is only being fired once. I'm using build: Version 2014.2494 (2014.11.5)

任何帮助都会非常有用!

由于

克里斯。

1 个答案:

答案 0 :(得分:0)

手动重新构建场景后,而不是在最新版本中使用compower UI,现在场景不再多次触发show()/ hide()/ create()/ destroy() - 奇怪!

作曲家ui中可能还有一些奇怪的错误?在corona SDK论坛上有一个解决这个问题的线程,现在将关闭它。

简而言之,我的解决方案是手动重新创建手动和定位对象,而不是在最新版本中使用计算机UI软件。