Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Help with rain

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9527

    Jaron

    I have rain already made into a SpriteSequence, but I am having trouble incorporating it into its actual use. I want the rain to play after the player gets a score of 15, 30, 45, 60, etc., and play for a certain amount of time. While it’s playing, I would also like it to effect the gravity.

    Not sure if the support forums help people code, but I would really appreciate some help. Thanks.

    #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 Felgo 3.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
          }
        }
      }
    }
    
    

     

    #9590

    Alex
    Felgo Team

    Hi Steve,

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

    
    import Felgo 3.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 8 years, 9 months ago by  Alex.
Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded