Forums

OverviewV-Play 2 Support (Qt 5)Help with rain › Reply To: Help with rain

OverviewV-Play 2 Support (Qt 5)Help with rain › Reply To: Help with rain
#9586

Vladyslav

Hello Steve,

I’m not quite sure what you meant by “I would also like it to effect the gravity”, but here is a code snippet you might find helpful. Press the mouse to increase the score. When the score is 15,30,45,60 the animation will be played for 3 seconds and then stop. Make sure to set all *** fieldsĀ corresponding your rain animation

import VPlay 2.0
import QtQuick 2.0

GameWindow {
  id: gameWindow
  property int score: 0
  
  Scene {
    id: scene
    width: 800
    height: 480
    
    SpriteSequenceVPlay {
      id: rainAnimation
      
      anchors.centerIn: parent
      defaultSource: "../assets/rain.png" // *** source file of your animation spritesheet
      
      visible: timer.running // when the time is over we hide the animation
      
      SpriteVPlay {
        name: "shooting"
        frameWidth: 256 // *** width of only one frame
        frameHeight: 256 // *** height of only one frame
        frameCount: 4 // *** number of frames in the animation
        frameRate: 10
      }
      
    }
    // 
    MouseArea{
      anchors.fill: parent
      onPressed: {
        score = score + 5 // increase the score on every click
        if(timer.running === false && score%15 == 0) // if the animation is not running and score is %15 == 0 (15,30,45...) 
          timer.running = true // start the animation
      }
    }
    
    // a test Text component to check the score
    Text{
      color: "orange"
      text: score
      font.pixelSize: 64
    }
    
    Timer {
      id: timer
      interval: 3000 // how long to play the animation
      running:false
      repeat:true
      onTriggered: {
        running = false // turn off the animation after the time is over
      }
    }
  }
}

 

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