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
#9590

Alex
V-Play Team

Hi Steve,

here is another possible solution, without SpriteSequence, using the Qt particle system:


import VPlay 2.0
import QtQuick 2.0
import QtQuick.Particles 2.0

GameWindow {
  id: gameWindow
  
  activeScene: scene
  
  width: 960
  height: 640
  
  Scene {
    id: scene
    
    width: 480
    height: 320
    
    Rectangle {
      anchors.fill: parent
      color: "black"
    }
    
    MouseArea {
      anchors.fill: parent
      onClicked: {
        rainTimer.start()
      }
    }
    
    Timer {
      id: rainTimer
      interval: 3000
    }
    
    ParticleSystem {
      id: particles
      running: true
    }
    ItemParticle {
      system: particles
      fade: false
      delegate: Rectangle {
        width: 2
        height: 10
        color: "white"
        opacity: 0.6
      }
    }
    
    Emitter {
      // enable the particles as long as the timer is running
      enabled: rainTimer.running
      system: particles
      emitRate: 60
      lifeSpan: 3000
      velocity: PointDirection { y:240; yVariation: 60; }
      size: 3
      sizeVariation: 4
      width: parent.width
      anchors.horizontalCenter: parent.horizontalCenter
      height: 1
      anchors.bottom: parent.top
    }
    
    PhysicsWorld {
      // if it's raining, the gravity is -20, else it's -10
      // this does not affect the particles, it's just to answer your question
      gravity.y: rainTimer.running ? -20 : -10
    }
  }
}

If you click on the screen, we start a timer that is running for 3 seconds. While the timer is running we spawn rain particles and change the gravity of the physicsworld. I used an ItemParticle for demonstration purposes, you would most likely swap this one for an ImageParticle with a rain drop particle image.

Cheers,
Alex

  • This reply was modified 3 years, 1 month ago by  Alex.

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