Forums

OverviewV-Play 1 Support › Loading Scenes from GameWindow on Button press

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4268

    phil.jahoda

    Hi

    I have a gamewindow, and in it I declared various Scenes.
    One Scene for menu, one Scene for Game, …

    What I want to do is display the Menu Scene by default, which shows various buttons.
    From these Buttons, I then what to load other Scenes to be displayed in the GameWindow.

    How do I do that?

    Main.qml
    GameWindow {

    id: window

    MenuScene { ... }

    GameScene { ... }

    // and so on...
    }

    MenuScene.qml


    MenuScene {

    id: mainMenu

    Button { ... } // should load the game scene
    Button { ... } // should load some other scene

    }
     

    #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

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

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