MainItem.qml Example File

demos/FlappyBird/qml/MainItem.qml
 import Felgo 3.0
 import QtQuick 2.0
 import "scenes"
 import "common"

 Item {
   id: mainItem
   property alias audioManager: audioManager
   property alias entityManager: entityManager
   property alias gameNetwork: felgoGameNetworkScene.gameNetwork

   // for easier reference from GameOverScreen
   property int highscore: gameNetwork.userHighscoreForCurrentActiveLeaderboard
   property int coins

   // global music and sound management
   AudioManager {
     id: audioManager
   }

   MenuScene {
     id: menuScene
     onGamePressed: {
       mainItem.state = "game"
     }
     onNetworkPressed: {
       felgoGameNetworkScene.initialStateBeforeShow = "menu"
       mainItem.state = "gameNetwork"
     }

     onBackButtonPressed: {
       nativeUtils.displayMessageBox("Really quit the game?", "", 2);
     }

     Connections {
       // nativeUtils should only be connected, when this is the active scene
       target: window.activeScene === menuScene ? nativeUtils : null
       onMessageBoxFinished: {
         if(accepted) {
             Qt.quit()
         }
       }
     }
   }

   GameScene {
     id: gameScene

     onMenuPressed: {
       mainItem.state = "menu"
     }
     onNetworkPressed: {
       felgoGameNetworkScene.initialStateBeforeShow = "game"
       mainItem.state = "gameNetwork"
     }
     onUseCoinsPressed: {
     }
   }

   FelgoGameNetworkScene {
     id: felgoGameNetworkScene
     onBackButtonPressed: {
       // go back to the state from where it was called
       mainItem.state = felgoGameNetworkScene.initialStateBeforeShow
     }
   }

   EntityManager {
     id: entityManager
     // entities shall only be created in the gameScene
     entityContainer: gameScene.entityContainer
   }

   state: "menu"

   states: [
     State {
       name: "menu"
       PropertyChanges {target: menuScene; opacity: 1}
       PropertyChanges {target: window; activeScene: menuScene}
       StateChangeScript {
         script: {
           audioManager.play(audioManager.idSWOOSHING)
         }
       }
     },
     State {
       name: "gameNetwork"
       PropertyChanges {target: felgoGameNetworkScene; opacity: 1}
       PropertyChanges {target: window; activeScene: felgoGameNetworkScene}
     },
     State {
       name: "game"
       PropertyChanges {target: gameScene; opacity: 1}
       PropertyChanges {target: window; activeScene: gameScene}
       StateChangeScript {
         script: {
           gameScene.enterScene()
           audioManager.play(audioManager.idSWOOSHING)
         }
       }
     }
   ]
 }

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