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.
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
}
}
}
}
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, 2 months ago by Alex.
By signing up, you consent to Felgo processing your data & contacting you to fulfill your request. For more information on how we are committed to protecting & respecting your privacy, please review our privacy policy.
Want to find out if Felgo is a good fit for your company?
As part of the free Business evaluation, we offer a free welcome call for companies, to talk about your requirements, and how the Felgo SDK & Services can help you. Just sign up and schedule your call.
Sign up now to start your free Business evaluation: