MultiSceneMultiLevelMain.qml Example File

demos/MultiSceneMultiLevel/qml/MultiSceneMultiLevelMain.qml
 import Felgo 3.0
 import QtQuick 2.0
 import "scenes"

 GameWindow {
   id: window
   screenWidth: 960
   screenHeight: 640

   // You get free licenseKeys from https://felgo.com/licenseKey
   // With a licenseKey you can:
   //  * Publish your games & apps for the app stores
   //  * Remove the Felgo Splash Screen or set a custom one (available with the Pro Licenses)
   //  * Add plugins to monetize, analyze & improve your apps (available with the Pro Licenses)
   //licenseKey: "<generate one from https://felgo.com/licenseKey>"

   // create and remove entities at runtime
   EntityManager {
     id: entityManager
   }

   // menu scene
   MenuScene {
     id: menuScene
     // listen to the button signals of the scene and change the state according to it
     onSelectLevelPressed: window.state = "selectLevel"
     onCreditsPressed: window.state = "credits"
     // the menu scene is our start scene, so if back is pressed there we ask the user if he wants to quit the application
     onBackButtonPressed: {
       nativeUtils.displayMessageBox(qsTr("Really quit the game?"), "", 2);
     }
     // listen to the return value of the MessageBox
     Connections {
       target: nativeUtils
       onMessageBoxFinished: {
         // only quit, if the activeScene is menuScene - the messageBox might also get opened from other scenes in your code
         if(accepted && window.activeScene === menuScene)
           Qt.quit()
       }
     }
   }

   // scene for selecting levels
   SelectLevelScene {
     id: selectLevelScene
     onLevelPressed: {
       // selectedLevel is the parameter of the levelPressed signal
       gameScene.setLevel(selectedLevel)
       window.state = "game"

     }
     onBackButtonPressed: window.state = "menu"
   }

   // credits scene
   CreditsScene {
     id: creditsScene
     onBackButtonPressed: window.state = "menu"
   }

   // game scene to play a level
   GameScene {
     id: gameScene
     onBackButtonPressed: window.state = "selectLevel"
   }

   // menuScene is our first scene, so set the state to menu initially
   state: "menu"
   activeScene: menuScene

   // state machine, takes care reversing the PropertyChanges when changing the state, like changing the opacity back to 0
   states: [
     State {
       name: "menu"
       PropertyChanges {target: menuScene; opacity: 1}
       PropertyChanges {target: window; activeScene: menuScene}
     },
     State {
       name: "selectLevel"
       PropertyChanges {target: selectLevelScene; opacity: 1}
       PropertyChanges {target: window; activeScene: selectLevelScene}
     },
     State {
       name: "credits"
       PropertyChanges {target: creditsScene; opacity: 1}
       PropertyChanges {target: window; activeScene: creditsScene}
     },
     State {
       name: "game"
       PropertyChanges {target: gameScene; opacity: 1}
       PropertyChanges {target: window; activeScene: gameScene}
     }
   ]
 }

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