Dark screen while reloading scene

The code for reset button widget includes

composer.removeScene(“level1”)

composer.gotoScene(“level1”)

and there is a black screen while scene reloading.

Preview:

http://imagestun.com/hosting/?v=untitlrcr.gif

How to treat that stunning blinking? :slight_smile:

May be use cutscene like Ponywolf do in Sticker-Knight-Platformer

Sticker-Knight-Platformer/scene/refresh.lua

-- Include modules/libraries local composer = require( "composer" ) -- Variables local to scene local prevScene = composer.getSceneName( "previous" ) -- Create a new Composer scene local scene = composer.newScene() function scene:show( event ) local phase = event.phase local options = { params = event.params } if ( phase == "will" ) then composer.removeScene( prevScene ) elseif ( phase == "did" ) then composer.gotoScene( prevScene, options ) end end scene:addEventListener( "show", scene ) return scene

ldurniat

Is that button located in the scene “level1”? You really should not be removing the scene you’re currently in. Maybe share more details about how your game flows.

Rob

Yes, the button is located in this scene. It should be made as a widget and a question is: what function i should place after  then  to reset items positions…

–Function to reload

local function sceneReload()

???

end

–Reload button widget

local widgetReload = require (“widget”)

– Function to handle button events

local function handleReload (event)

  if (“ended” == event.phase) then

 sceneReload() 

  end

end

– Image sheet options and declaration

– Create the widget

We don’t know a lot about how your game/app is supposed to flow. In fact we don’t know anything about it so it’s going to be really, really hard to offer you any solid advice, but I’m going to be making some assumptions:

  1. You’re building a game

  2. You will have a condition where the player looses and you want to let them play again

  3. You want to simplify the reloading process.

You have two realistic choices.

  1. Stay in the same scene and have your reload/reset button reposition objects, reset variables, update on screen text, etc.  In this case, you are responsible for writing all the code to reposition/reset everything. There is no quick 2-line short cut to reset this. Removing the scene you are currently in will result in blanking everything and causing this flash.

  2. Use a “cut-scene”. If you think about the classic game PacMan, when a level is complete or you get busted by ghost, you’re taken to a temporary scene that says “You lost, play again?” Or “You won, next level?”.  Or you might play an animation of Mr. PacMan and Ms. PacMan dancing around the screen.  These cut-scene’s serve a big purpose. They let you reset your game scene in the background. In Corona that means you can use composer.removeScene(“level1”); composer.gotoScene(“level1”) which is the short cut to reseting the game scene.

If it were me, when you reach a condition in level1 where the game is over and you want to reset it, go to your levelover scene. Your reset button can be in this scene and it can go back to level1.

Since we haven’t seen your UI or what game objects make up your game, doing an in-scene reset (option1) could be a few lines of code or it could be hundreds depending on the complexity of your game scene. Do you have objects that take damage? Do you have enemies that would need removed? Do you need to not only set the X, Y of an object but make sure it’s rotation is back to its starting point? It can be a lot of work to manually reset the scene.  The cut-scene method is above and by far the easiest way to manage this.

Rob

Thank you for your detailed advice, Rob.

Let me try to describe the game flow in a few words. A player has some special cards (pocket interactive doors to other worlds, like in Roger Zelazny’s Chronicles of Amber), four cards for the beginning and up to 100 at the final level.

But to use them, they must be placed on the desk in a correct order. Correct means only one right place for every card.

So, more cards, more difficult to solve the puzzle. I suppose that for the player it would be suitable not to reload a whole scene or get a temporary scene to see a result. When he notice something wrong in his desicion, he could make a reset, i. e. return cards to the initial stage on the desk.

In that case, I probably would not do a scene reload at all. There is no reason to destroy and rebuild your user interface (UI), or even destroy and re-create the cards. I would just have your reload/reset function move cards back to their original spot and reset any variables that you need.

Rob

I couldn’t understand how to separate scene reset and items reloading. That’s why i had to use composer.removeScene and composer.gotoScene inside a function, which should be used inside a button widget…  :wacko:  seems, it was a wrong way.

May be use cutscene like Ponywolf do in Sticker-Knight-Platformer

Sticker-Knight-Platformer/scene/refresh.lua

-- Include modules/libraries local composer = require( "composer" ) -- Variables local to scene local prevScene = composer.getSceneName( "previous" ) -- Create a new Composer scene local scene = composer.newScene() function scene:show( event ) local phase = event.phase local options = { params = event.params } if ( phase == "will" ) then composer.removeScene( prevScene ) elseif ( phase == "did" ) then composer.gotoScene( prevScene, options ) end end scene:addEventListener( "show", scene ) return scene

ldurniat

Is that button located in the scene “level1”? You really should not be removing the scene you’re currently in. Maybe share more details about how your game flows.

Rob

Yes, the button is located in this scene. It should be made as a widget and a question is: what function i should place after  then  to reset items positions…

–Function to reload

local function sceneReload()

???

end

–Reload button widget

local widgetReload = require (“widget”)

– Function to handle button events

local function handleReload (event)

  if (“ended” == event.phase) then

 sceneReload() 

  end

end

– Image sheet options and declaration

– Create the widget

We don’t know a lot about how your game/app is supposed to flow. In fact we don’t know anything about it so it’s going to be really, really hard to offer you any solid advice, but I’m going to be making some assumptions:

  1. You’re building a game

  2. You will have a condition where the player looses and you want to let them play again

  3. You want to simplify the reloading process.

You have two realistic choices.

  1. Stay in the same scene and have your reload/reset button reposition objects, reset variables, update on screen text, etc.  In this case, you are responsible for writing all the code to reposition/reset everything. There is no quick 2-line short cut to reset this. Removing the scene you are currently in will result in blanking everything and causing this flash.

  2. Use a “cut-scene”. If you think about the classic game PacMan, when a level is complete or you get busted by ghost, you’re taken to a temporary scene that says “You lost, play again?” Or “You won, next level?”.  Or you might play an animation of Mr. PacMan and Ms. PacMan dancing around the screen.  These cut-scene’s serve a big purpose. They let you reset your game scene in the background. In Corona that means you can use composer.removeScene(“level1”); composer.gotoScene(“level1”) which is the short cut to reseting the game scene.

If it were me, when you reach a condition in level1 where the game is over and you want to reset it, go to your levelover scene. Your reset button can be in this scene and it can go back to level1.

Since we haven’t seen your UI or what game objects make up your game, doing an in-scene reset (option1) could be a few lines of code or it could be hundreds depending on the complexity of your game scene. Do you have objects that take damage? Do you have enemies that would need removed? Do you need to not only set the X, Y of an object but make sure it’s rotation is back to its starting point? It can be a lot of work to manually reset the scene.  The cut-scene method is above and by far the easiest way to manage this.

Rob

Thank you for your detailed advice, Rob.

Let me try to describe the game flow in a few words. A player has some special cards (pocket interactive doors to other worlds, like in Roger Zelazny’s Chronicles of Amber), four cards for the beginning and up to 100 at the final level.

But to use them, they must be placed on the desk in a correct order. Correct means only one right place for every card.

So, more cards, more difficult to solve the puzzle. I suppose that for the player it would be suitable not to reload a whole scene or get a temporary scene to see a result. When he notice something wrong in his desicion, he could make a reset, i. e. return cards to the initial stage on the desk.

In that case, I probably would not do a scene reload at all. There is no reason to destroy and rebuild your user interface (UI), or even destroy and re-create the cards. I would just have your reload/reset function move cards back to their original spot and reset any variables that you need.

Rob

I couldn’t understand how to separate scene reset and items reloading. That’s why i had to use composer.removeScene and composer.gotoScene inside a function, which should be used inside a button widget…  :wacko:  seems, it was a wrong way.