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

Numbers.qml Example File

demos/FlappyBird/qml/game/Numbers.qml
 import Felgo 3.0
 import QtQuick 2.0
 import "../entities"

 Item {
   id: numbers
   width: row.width
   height: row.heigth
   property string color
   property int number: 0

   property string imagePath: "../../assets/img/"

   function truncate(_value)
   {
     if (_value<0) return Math.ceil(_value);
     else return Math.floor(_value);
   }

   onNumberChanged: {
     if(number > 9999) number = 9999
     var trailingZero = true

     var unit = truncate((number / 1000) % 10)
     if((trailingZero && unit <= 0) || unit >= 10) {
       position1000.source = imagePath + "empty_big.png"
     } else {
       trailingZero = false
       position1000.source = imagePath + unit+"_big"+color+".png"
     }

     unit = truncate((number / 100) % 10)
     if((trailingZero && unit <= 0) || unit >= 10) {
       position100.source = imagePath + "empty_big.png"
     } else {
       trailingZero = false
       position100.source = imagePath + unit+"_big"+color+".png"
     }

     unit = truncate((number / 10) % 10)
     if((trailingZero && unit <= 0) || unit >= 10) {
       position10.source = imagePath + "empty_big.png"
     } else {
       position10.source = imagePath + unit+"_big"+color+".png"
     }

     unit = truncate(number % 10)
     // test also if there is remainder, if no remainder it might be 10 and the first number is needed, otherwise a fragment is displayed.
     if(number % 10 && ((trailingZero && unit <= 0) || unit >= 10)) {
       position1.source = imagePath + "empty_big.png"
     } else {
       position1.source = imagePath + unit+"_big"+color+".png"
     }

     if(number <= 0) {
       position1.source = imagePath + "0_big"+color+".png"
     }
   }

   Row {
     id: row
     height: position1.height
     x: number >= 1000 ? -12 : number >= 100 ? -24 : number >= 10 ? -36 : -48

     MultiResolutionImage {
       id: position1000
       source: imagePath + "empty_big.png"
     }
     MultiResolutionImage {
       id: position100
       source: imagePath + "empty_big.png"
     }
     MultiResolutionImage {
       id: position10
       source: imagePath + "empty_big.png"
     }

     MultiResolutionImage {
       id: position1
       source: imagePath + "0_big"+color+".png"
     }
   }
 }

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