Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

R.U.B.E. Editor - Side Scroller

 import Felgo 4.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: event => {
     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: Qt.resolvedUrl("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
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded