I’m having great fun while reading your posts. Dig the style.
Anyway. Instead of composer.removeScene, I’d suggest another approach. Instead of removing the current scene and calling it again in the same function, I’d suggest a simple transition screen. Here is an example project.
example.zip (1.5 KB)
Not the best code or the best approach but works for me. You may need to change some parts to fit your need though.
1 Like
Thank you, @bgmadclown, I’ll be dig.
P. S. @bgmadclown, I like your “example”. I added a little local square in the center of background at gameScene and anotherGroup:insert (square). Then I added transition.to (square, {time = 1500, x = math.random (0, display.contentWidth), y = math.random (0, display.contentHeight)}). Your method works perfectly. But, if the random square.y = display.contentHeight, after reloading scene I can see a half of square left at the bottom of the scene. I might have to experiment more!
1 Like
Another option is to never leave that current scene. Move all of your code that sets up the scene out of the create function, and that way you can call it again when you want to reset the scene. Ditch all of the created objects and then call your set up function again when you want to try again.
I try to never put much code at all inside of the create, show, hide composer functions. That way I have options available to me.
4 Likes
@J_A_Whye one more question, would you clarify for me the flow of your method with an example or a visual scheme (cause I prefer Visual Learning Style, not Kinesthetic)
Could I say that I understood you by one of this flow tables?
OR
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == "will" then
elseif phase == "did" then
local previous = composer.getSceneName("previous")
if previous ~= "main" and previous then
composer.removeScene(previous, false)
end
end
end
This is the code I used to process the scene.
Remember to clean up all objects in the scene every time.
This code, you should be able to restart from “scene:create” every time.
1 Like
@vb66r55 t_h_a-n_k_s_a_l_o_t_!
Sorry for the delay. Looks like you got an answer to your problem, but for anyone else who happens by, this is what I meant:
local function setUpDisplay(sceneGroup)
-- create all display objects and such here
end
function scene:create(event)
setUpDisplay(self.view)
end
Basically, the less code inside the scene functions, the better I like it – the more options I have later on.
1 Like
@J_A_Whye
No problemo, I am still genuinely interested in the all possible methods. And, I’m sorry too for my irremediable idiocy. I can not catch this one (the last, but not the least) moment. How to reload a scene, after the reload button’s line: if (event.phase == ended)… Should I call setUpDisplay() function again?
Yes, you’d call SetUpDisplay() again, but usually after making sure to kill off whatever you created originally. For example, I have routines to kill any leftover enemies, plus anything else that might need to be recreated (level mazes, etc.). The easiest way to do that is put all enemies inside a specific display group, background images in a specific display group, and so on. Then just ditch those groups.
1 Like
Thank you so much. The solution was helpful to a great extent.