Forums

OverviewV-Play 1 SupportLoading Scenes from GameWindow on Button press › Reply To: Loading Scenes from GameWindow on Button press

OverviewV-Play 1 SupportLoading Scenes from GameWindow on Button press › Reply To: Loading Scenes from GameWindow on Button press
#4269

Christian
V-Play Team

Hi,

the easiest way to achieve this is by setting all scenes that you want not to display in the beginning to invisible, and change them to visible when the button is pressed (and set the active scene to invisible). You can achieve that by storing the current scene as a property variant. Another approach is using the states property in GameWindow: you can define in which states each of your scenes gets visible like the following code:

GameWindow {
 id: gameWindow

 MenuScene {
  id: menuScene
  visible: true // should be visible from the beginning

  Button {
    onClicked: gameWindow.state = "game" // switch to GameScene
  }

 }

 GameScene {
  id: gameScene
  visible: false // should only be visible in state game
 }

// the default state is "", and it sets the MenuScene to visible and gameScene invisible

states: [
    State {
      name: "game"
      PropertyChanges { target: gameScene; visible: true}
      PropertyChanges { target: menuScene; visible: false}
      StateChangeScript {
        script: {
          console.debug("entered state 'game'")
          console.debug("GameScene.visible:", gameScene.visible)
        }
      }// end of StateChangeScript
    }// end of State game
}// end of GameWindow

 

With this approach, both scenes are loaded at runtime. You could also load them when they are first needed with the Loader element. For more details, please see the ChickenOutbreak and Squaby demos in the V-PlaySDK in the Demos/V-Play SDK folder.

Cheers, Chris

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support