LUA/Corona sdk:storyboard.gotoScene()不工作
我是科罗纳和卢阿的新手,所以请耐心点。 所以我有一个主屏幕,我从我的主文件进入,它运行良好。然后我想从一个不同的sceen返回到那个sceen,但什么都没有发生(但是“胜利”正在垃圾邮件发送到我的控制台窗口) win功能:LUA/Corona sdk:storyboard.gotoScene()不工作,lua,coronasdk,Lua,Coronasdk,我是科罗纳和卢阿的新手,所以请耐心点。 所以我有一个主屏幕,我从我的主文件进入,它运行良好。然后我想从一个不同的sceen返回到那个sceen,但什么都没有发生(但是“胜利”正在垃圾邮件发送到我的控制台窗口) win功能: function win() print("win!"); storyboard.gotoScene( "MSCREEN.mscreen" ); end 我调用它的函数: function scene:enterFrame(inEvent) --so
function win()
print("win!");
storyboard.gotoScene( "MSCREEN.mscreen" );
end
我调用它的函数:
function scene:enterFrame(inEvent)
--some other stuff
if (ball.x>display.contentWidth and failFlag==false) then
win();
end
end
我的主要观点是:
local scene = storyboard.newScene();
local bg;
local text;
function scene:createScene(inEvent)
bg = display.newImage( "MSCREEN/bg.png");
bg.x = display.contentWidth / 2;
bg.y = display.contentHeight / 2;
text=display.newText( "Touch!", 0,0, fontName, 70);
text.x =display.contentWidth / 2 ;
text.y =display.contentHeight / 2 +230;
self.view:insert(bg);
self.view:insert(text);
end
function scene:enterFrame(inEvent)
tekstBujany(text);
end
function scene:touch(inEvent)
if inEvent.phase == "ended" then
storyboard.gotoScene( "JUMP.GJump" );
end
end
function scene:destroyScene(inEvent)
bg:removeSelf();
bg=nil;
text:removeSelf();
text=nil;
end -- End destroyScene().
scene:addEventListener("createScene", scene);
scene:addEventListener("destroyScene", scene);
Runtime:addEventListener("enterFrame", scene);
Runtime:addEventListener("touch",scene);
return scene;
已解决
所以加上
storyboard.purgeOnSceneChange = true;
玩了这个把戏,不知道为什么。小心win()函数,它看起来被调用了很多次。设置另一个变量并在方法中更改它
function win()
isNotWin = false -- so this method doesn't get called a lot of times.
print("win!")
storyboard.gotoScene( "MSCREEN.mscreen" )
end
function scene:enterFrame(inEvent)
--some other stuff
if (ball.x>display.contentWidth and failFlag==false and isNotWin == true) then
win();
end
end
小心使用win()函数,它看起来会被多次调用。设置另一个变量并在方法中更改它
function win()
isNotWin = false -- so this method doesn't get called a lot of times.
print("win!")
storyboard.gotoScene( "MSCREEN.mscreen" )
end
function scene:enterFrame(inEvent)
--some other stuff
if (ball.x>display.contentWidth and failFlag==false and isNotWin == true) then
win();
end
end
小心使用win()函数,它看起来会被多次调用。设置另一个变量并在方法中更改它
function win()
isNotWin = false -- so this method doesn't get called a lot of times.
print("win!")
storyboard.gotoScene( "MSCREEN.mscreen" )
end
function scene:enterFrame(inEvent)
--some other stuff
if (ball.x>display.contentWidth and failFlag==false and isNotWin == true) then
win();
end
end
小心使用win()函数,它看起来会被多次调用。设置另一个变量并在方法中更改它
function win()
isNotWin = false -- so this method doesn't get called a lot of times.
print("win!")
storyboard.gotoScene( "MSCREEN.mscreen" )
end
function scene:enterFrame(inEvent)
--some other stuff
if (ball.x>display.contentWidth and failFlag==false and isNotWin == true) then
win();
end
end
“enterFrame”事件在运行时对象的每一帧生成,因此大约每秒生成30到60次。因此,如果可能,将在每一帧调用win()。由于win()会导致转换到新场景,如果storyboard.purgeOnSceneChange=false,则会为每个场景调用enterFrame,从而导致win()调用流不断,转换流不断,并转换到同一场景“MSCREEN.MSCREEN”(这不太好)。o如果设置storyboard.purgeOnSceneChange=true,则会清除上一个场景,这里是使用enterFrame调用win()的场景,因此win()只会被调用一次
总之,设置storyboard.purgeOnSceneChange=true可能有效,但我认为这里的逻辑有一个问题:不应该在每一帧调用场景转换!如果要监视某个条件以声明win,则应删除win()中的enterFrame回调,或在调用win()一次后确保该条件为false:
function scene:enterFrame(inEvent)
if (ball.x > display.contentWidth and failFlag == false) then
win();
Runtime:removeEventListener("enterFrame", scene);
end
end
对于guard变量,它如下所示:
local winCalled = false
function win()
winCalled = true
...
end
function scene:enterFrame(inEvent)
if (ball.x > display.contentWidth and failFlag == false) then
win();
end
end
“enterFrame”事件在运行时对象的每一帧生成,因此大约每秒生成30到60次。因此,如果可能,将在每一帧调用win()。由于win()会导致转换到新场景,如果storyboard.purgeOnSceneChange=false,则会为每个场景调用enterFrame,从而导致win()调用流不断,转换流不断,并转换到同一场景“MSCREEN.MSCREEN”(这不太好)。o如果设置storyboard.purgeOnSceneChange=true,则会清除上一个场景,这里是使用enterFrame调用win()的场景,因此win()只会被调用一次
总之,设置storyboard.purgeOnSceneChange=true可能有效,但我认为这里的逻辑有一个问题:不应该在每一帧调用场景转换!如果要监视某个条件以声明win,则应删除win()中的enterFrame回调,或在调用win()一次后确保该条件为false:
function scene:enterFrame(inEvent)
if (ball.x > display.contentWidth and failFlag == false) then
win();
Runtime:removeEventListener("enterFrame", scene);
end
end
对于guard变量,它如下所示:
local winCalled = false
function win()
winCalled = true
...
end
function scene:enterFrame(inEvent)
if (ball.x > display.contentWidth and failFlag == false) then
win();
end
end
“enterFrame”事件在运行时对象的每一帧生成,因此大约每秒生成30到60次。因此,如果可能,将在每一帧调用win()。由于win()会导致转换到新场景,如果storyboard.purgeOnSceneChange=false,则会为每个场景调用enterFrame,从而导致win()调用流不断,转换流不断,并转换到同一场景“MSCREEN.MSCREEN”(这不太好)。o如果设置storyboard.purgeOnSceneChange=true,则会清除上一个场景,这里是使用enterFrame调用win()的场景,因此win()只会被调用一次
总之,设置storyboard.purgeOnSceneChange=true可能有效,但我认为这里的逻辑有一个问题:不应该在每一帧调用场景转换!如果要监视某个条件以声明win,则应删除win()中的enterFrame回调,或在调用win()一次后确保该条件为false:
function scene:enterFrame(inEvent)
if (ball.x > display.contentWidth and failFlag == false) then
win();
Runtime:removeEventListener("enterFrame", scene);
end
end
对于guard变量,它如下所示:
local winCalled = false
function win()
winCalled = true
...
end
function scene:enterFrame(inEvent)
if (ball.x > display.contentWidth and failFlag == false) then
win();
end
end
“enterFrame”事件在运行时对象的每一帧生成,因此大约每秒生成30到60次。因此,如果可能,将在每一帧调用win()。由于win()会导致转换到新场景,如果storyboard.purgeOnSceneChange=false,则会为每个场景调用enterFrame,从而导致win()调用流不断,转换流不断,并转换到同一场景“MSCREEN.MSCREEN”(这不太好)。o如果设置storyboard.purgeOnSceneChange=true,则会清除上一个场景,这里是使用enterFrame调用win()的场景,因此win()只会被调用一次
总之,设置storyboard.purgeOnSceneChange=true可能有效,但我认为这里的逻辑有一个问题:不应该在每一帧调用场景转换!如果要监视某个条件以声明win,则应删除win()中的enterFrame回调,或在调用win()一次后确保该条件为false:
function scene:enterFrame(inEvent)
if (ball.x > display.contentWidth and failFlag == false) then
win();
Runtime:removeEventListener("enterFrame", scene);
end
end
对于guard变量,它如下所示:
local winCalled = false
function win()
winCalled = true
...
end
function scene:enterFrame(inEvent)
if (ball.x > display.contentWidth and failFlag == false) then
win();
end
end
谢谢,我确信在第一次调用goToScene后,输入帧已停止。正如我所能说的,我认为保持storyboard.purgeOnSceneChange=true是个好主意(我有很多sceens),对吗?@yeris您的解决方案有效,但由于您使用的设置有一个幸运的副作用,所以我只想给您另一个选项,以防您正在寻找更强大的解决方案。我希望你能发现在你的技巧袋里增加一些有用的东西。是的,我改变了它,我的意思是整个逻辑。我只是想知道保持storyboard.purgeOnSceneChange=true是否是一个好主意。@yeris如果您想在每次转换到另一个场景时释放当前场景所使用的资源,则毫无例外。所以我想说,它应该只在内存不足或存在其他性能问题的情况下使用。谢谢