RubeSideScrollerMain.qml Example File

demos/RubeSidescroller/qml/RubeSideScrollerMain.qml
 import Felgo 3.0
 import QtQuick 2.0

 GameWindow {
   id: gameWindow

   // 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>"

   activeScene: scene

   // the size of the Window can be changed at runtime by pressing Ctrl (or Cmd on Mac) + the number keys 1-8
   // the content of the logical scene size (480x320 for landscape mode by default) gets scaled to the window size based on the scaleMode
   // you can set this size to any resolution you would like your project to start with, most of the times the one of your main target device
   // this resolution is for iPhone 4 & iPhone 4S
   screenWidth: 960
   screenHeight: 640

   // load a level at game startup
   Component.onCompleted: {
     physicsWorld.running = true
     loadLevel()
   }

   // handle key input
   onKeyPressedGlobally: {
     var camMoveSpeed = 10
     if (event.modifiers & Qt.KeypadModifier) {
       if (event.key === Qt.Key_4){
         level.x += camMoveSpeed
       }
       if (event.key === Qt.Key_6){
         level.x -= camMoveSpeed
       }
       if (event.key === Qt.Key_8){
         level.y += camMoveSpeed
       }
       if (event.key === Qt.Key_2){
         level.y -= camMoveSpeed
       }
       if (event.key === Qt.Key_Plus){
         level.scale /= 0.9
       }
       if (event.key === Qt.Key_Minus){
         level.scale *= 0.9
       }
     }
   }

   Scene {
     id: scene

     // the "logical size" - the scene content is auto-scaled to match the GameWindow size
     width: 480
     height: 320

     property alias mouseArea: mouseArea
     property alias level: level

     EntityManager {
       id: entityManager
       entityContainer: level
     }

     Item {
       id: level

       PhysicsWorld {
         id: physicsWorld

         // physics is disabled initially, and enabled after the splash is finished
         running: false
         //gravity.y: -9.81 // this is set from rube anyways, no need to set it here
         z: 10 // draw the debugDraw on top of the entities

         // these are performance settings to avoid boxes colliding too far together
         // set them as low as possible so it still looks good
         updatesPerSecondForPhysics: 60
         velocityIterations: 5
         positionIterations: 5
         // set this to true to see the debug draw of the physics system
         // this displays all bodies, joints and forces which is great for debugging
         debugDrawVisible: false
       }
     }

     // rube parsers allows to load json files and dynamically create the game entities
     RubeParser {
       id: parser
       // relative path from this qml file to the entities folder
       entitiesFolder: "entities/"
     }

     MouseArea {
       id: mouseArea
       anchors.fill: scene.gameWindowAnchorItem
     }

     Row {
       spacing: 4
       GameButton {
         text: "Reload Rube Level"
         onClicked: {
           console.debug("start loading level")
           // call clearLevel first to start with a new level
           parser.clearLevel()

           loadLevel()
         }
       }
       GameButton {
         text: "Unload Rube Level"
         onClicked: {
           console.debug("start un-loading level")
           parser.clearLevel()
         }
       }
       GameButton {
         text: "Zoom In"
         onClicked: {
           level.scale /= 0.9
         }
       }
       GameButton {
         text: "Zoom Out"
         onClicked: {
           level.scale *= 0.9
         }
       }
     }
   }

   // loads the rube-level from a json file
   function loadLevel() {
     parser.setupLevelFromJSON(Qt.resolvedUrl("../assets/sidescroller.json"), physicsWorld, level)

     level.y = scene.height / 2
     level.x = scene.width / 2
   }
 }

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