Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / [SOLVED] Changing Scenes causes trouble

Author
Message
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 3rd Jan 2022 01:52 Edited at: 3rd Jan 2022 13:29
Hi there again!

I am currently adding a menu scene to my test game and I'm having already trouble, even though I want to add even two more scenes on top of that.

I have the problem that the sprites of the one scene remain in the other scene and are still being depicted.
Calling "Scene_cleanup()" doesn't do anything. Even when I set every sprite of the scene to invisible, they are still being depicted.

So I'm having my "game scene" and my "menu scene". When I changed the scene from "game" to "menu" it actually worked fine. I just had to call GameScene_cleanup() to clear the sprites. But now that I start the game with the menu scene first, the sprites are overlapping when changing back to the "game scene".

The entire script is quite long and probably hard to read, so I tried to include only the parts that I think could be relevant to this problem. And hoping that it's enough to detect the problem:



When I press the virtual "Play" button, the game scene (pond.scene) starts running, but the old sprites remain for some reason.
Thanks for any tips in advance.

The author of this post has marked a post as an answer.

Go to answer

jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 3rd Jan 2022 15:36
Here is basic example of the way I use to get a multiple scenes. Essentially to load a scene use sceneName_setup(). To unload a scene use sceneName_cleanup(). While in said scene you need to call sceneName_sync() in the main loop.


Attachments

Login to view attachments
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 3rd Jan 2022 16:36 Edited at: 3rd Jan 2022 16:37
Hey jd_zoo!

Thanks for the code sample!

Quote: "
Essentially to load a scene use sceneName_setup(). To unload a scene use sceneName_cleanup(). While in said scene you need to call sceneName_sync() in the main loop.
"

The thing is that's exactly what I did!
Just that I structured my script differently than yours.

I suppose I will isolate the relevant parts of my code to find out why it's not working, and possibly compare it with your code.
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 3rd Jan 2022 16:48 Edited at: 4th Jan 2022 02:17
This post has been marked by the post author as the answer.
Oh I got it!

My basic menu structure is like this (simplified):



I thought if I call the function "Break()", it would break out of the if statements completely, but it doesn't. So after I called "MenuScene_cleanup()", it still called "MenuScene_sync()" one last time before switching to the game scene loop. That's why it still got drawn unto the screen "after" I called "MEnuScene_cleanup()".

Interesting side note: It still got depicted after I set all the sprites to invisible, so that would mean that scene_cleanup() doesn't only remove all drawings unto the screen, but also resets all sprites to visible, right?

Anyways, the solution is to simply call Scene_sync() before the condition that changes the scene, so you don't draw the scene one last time after cleaning it:

jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 4th Jan 2022 00:02
Yeah ok so Break() is for the debugger, no? Its not going to stop your game loop (someone correct me if I'm wrong) so yes you would need to make sure the sceneA_sync() doesn't get called after sceneA_cleanup().
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 4th Jan 2022 02:12
Ah ok, I didn't know that! I just assumed it works like python where "break" gets you out of a loop/statement.

Login to post a reply

Server time is: 2024-04-20 07:42:15
Your offset time is: 2024-04-20 07:42:15