As I actually expected the problem was with my code. One of the best ways to solve a coding problem is to simplify. So I wrote a very simple test app with two scenes, one button on each and was able to go back and forth between the scenes by pressing the buttons. Here is the code in case it helps anybody
// Project: Scene Reuse
// Created: 19-08-15
#include "Scene1.scene"
#include "Scene2.scene"
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "SceneReuse" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
sceneNo as integer
// No initial scene
sceneNo = -1
do
Print( ScreenFPS() )
// Setup scene 1
if sceneNo = -1
sceneNo = 1
Scene1_setup()
endif
// Change to scene 2
if sceneNo = 1
if GetVirtualButtonPressed(Scene1_Button1) = 1
Scene1_cleanup()
Scene2_setup()
sceneNo = 2
endif
endif
// Change to scene 1
if sceneNo = 2
if GetVirtualButtonPressed(Scene2_Button1) = 1
Scene2_cleanup()
Scene1_setup()
sceneNo = 1
endif
endif
Sync()
loop
[Original Post]
Hi, I'm experimenting with scenes and was wondering how to go about having a game which would have one scene for setting game options such level of difficulty etc., and then the main scene which would be the game itself.
I would like it that from the game a player could quit and be taken back to the settings scene so they could start a new game perhaps at a different skill level.
I have tried calling the function LevelSelection_cleanup() after the user has made his or her selection (which closes the scene and deletes all the sprites) and thought I could then call LevelSelection_setup() to re-create this level selection scene when required. The problem with this approach is that I get an error message about virtual button 1 already existing in another scene. I think it's that AGKS starts creating virtual button Id's from 1 without considering if they are already in use in other scenes.
I have looked to see if there are commands for hiding scenes, but I didn't find any.
Maybe I am misunderstanding how to use scenes, but this seemed an easier way of creating user input forms that could be created and closed at will. I suppose I could design the layout with the scene editor and then copy the script and use that in my code.
Does anyone have any better ideas?
Cheers.
I have very simple tastes, I am always satisfied with the very best.
Oscar Wilde.