Mushroom.qml Example File

demos/PlatformerWithLevelEditor/qml/entities/Mushroom.qml
 import QtQuick 2.0
 import Felgo 3.0
 import "../editorElements"

 PlatformerEntityBaseDraggable {
   id: mushroom
   entityType: "mushroom"

   // this property is true when the player collected the mushroom
   property bool collected: false

   // when the mushroom is collected, it shouldn't be visible anymore
   image.visible: !collected

   // define colliderComponent for collision detection while dragging
   colliderComponent: collider

   // set image
   image.source: "../../assets/powerups/mushroom.png"

   BoxCollider {
     id: collider

     // make the collider a little smaller than the sprite
     width: parent.width - 2
     height: parent.height - 2
     anchors.centerIn: parent

     // disable collider when mushroom is collected
     active: !collected

     // the collider is static (shouldn't move) and only test
     // for collisions
     bodyType: Body.Static
     collisionTestingOnlyMode: true

     // Category6: powerup
     categories: Box.Category6
     // Category1: player body
     collidesWith: Box.Category1
   }

   function collect() {
     console.debug("collect mushroom")
     mushroom.collected = true

     audioManager.playSound("collectMushroom")
   }

   // reset mushroom
   function reset() {
     mushroom.collected = false
   }
 }

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