V-Play has a new name, say hi to Felgo!Learn More

Player.qml Example File

demos/FlappyBird/qml/entities/Player.qml
 import QtQuick 2.0
 import Felgo 3.0

 EntityBase {
   id: player
   entityType: "player"

   property real upwardforce: -280
   property int resetX: 0
   property int resetY: 0

   width: collider.radius * 2
   height: collider.radius * 2

   signal gameOver()

   Component.onCompleted: reset()

   onGameOver: {
     spriteSequence.running = false
   }

   SpriteSequence {
     id: spriteSequence

     anchors.centerIn: parent

     Sprite {
       name: "idle"
       frameCount: 3
       frameRate: 10

       frameWidth: 34
       frameHeight: 24
       source: "../../assets/img/birdSprite.png"
     }
     rotation: wabbleX.running ? 0 : collider.linearVelocity.y/10
   }

   CircleCollider {
     id: collider

     radius: spriteSequence.height/2
     bodyType: Body.Dynamic
   }

   function reset() {
     player.x = resetX
     player.y = resetY
     collider.body.linearVelocity = Qt.point(0,0)
     activateWabbling()
     spriteSequence.running = true
   }

   function push() {
     wabbleX.stop()
     wabbleY.stop()
     audioManager.play(audioManager.idWING)
     collider.body.linearVelocity = Qt.point(0,0)
     var localForwardVector = collider.body.toWorldVector(Qt.point(0, upwardforce));
     collider.body.applyLinearImpulse(localForwardVector, collider.body.getWorldCenter());
   }

   NumberAnimation on x {running: false; id: wabbleX; duration: 4000; loops: Animation.Infinite; easing.type: Easing.CosineCurve}
   NumberAnimation on y {running: false; id: wabbleY; duration: 4000; loops: Animation.Infinite; easing.type: Easing.SineCurve}

   function activateWabbling() {
     var wableVal = 25
     var rand = Math.random()
     var dir = (rand < 0.5 ? -wableVal/4*rand : wableVal/4*rand )
     wabbleX.from = player.x+dir
     wabbleX.to = player.x-dir
     wabbleX.start()
     rand = Math.random()
     dir = (rand < 0.5 ? -wableVal*rand : wableVal*rand )
     wabbleY.from = player.y+dir
     wabbleY.to = player.y-dir
     wabbleY.start()
   }
 }

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