QT Mobile Application Development (IV): applying particle effects

Source: Internet
Author: User

QT Mobile Application Development (IV): applying particle effects

The previous article describes how QT quick supports frame animations. The realization of frame animation is inseparable from state machine, while state machine, animation and state switch (transitions) are the core content of QT framework, which means that they can be built in any Qobject object without having to rely on QT for any graphics display module. Take an example and say, if you want to achieve a smooth transition of the background music, you can not write extra code, the volume of the background music animation interpolation can achieve the effect. The fact that I made the game "take Medicine" is how it works. And this article will focus on the QT quick another very powerful system-particle system.

original article, against undeclared references. Original Blog address:http://blog.csdn.net/gamesdev/article/details/34114501

Thanks to the understanding and abstraction of the particle system by QT Quick, we can use the particle system to make a lot of powerful effects, although the official examples are only those of the particles, but we can customize the vertex shader and the fragment shader to support 3D example effects.

The following is a QT-brought particle system demo program:


And it's not hard to make such a beautiful particle system. Next we'll create a simple project to look at:

import QtQuick 2.2import qtquick.controls 1.1import qtquick.particles 2.0ApplicationWindow {visible:true width:640 he                ight:480 title:qstr ("Test particle system") menubar:menubar {menu {title:qstr ("file") MenuItem {            Text:qstr ("Exit") OnTriggered:Qt.quit (); }}} particlesystem {anchors.centerIn:parent imageparticle {source: "Q  Rc:///particleresources/fuzzydot.png "colorvariation:1.0} Emitter {emitrate: Size:10 lifespan:4000 velocity:angledirection {Magnitud        E:100 anglevariation:360}}} Text {Anchors.right:parent.right Anchors.bottom:parent.bottom Text:qstr ("This example is used to test the particle System")}} 

The effect of the program is as follows:

So from the above demo program we can tell that a particle system is basically composed of Particlesystem, imageparticle and emitter. Particlesystem is essential because it is necessary to control the various particle system components. If Particlesystem is not present as the parent of emitter, then emitter has a member system that must specify the ID of the Particlesystem. Emitter is also an essential class, and its role is to specify how these examples are emitted, and specify the size and life cycle of the particles. And Imageparticle is the subclass of Particlepainter, it is not necessary, we can use particlepainter other subclasses customparticle and itemparticle to specify. Its role is to specify the picture of the particles as well as the rotation, color, transparency and other information.

In fact, in addition to the three, there is a class that can not be ignored, that is affector. In general, particles will maintain their initial velocity, acceleration, and size after emitter, and these values are no longer controlled by emitter, and only affector can control the size of the particles during operation. Here Affector is just a base class, which defines a lot of subclasses based on different effects. such as age, attractor, friction, Gravity, Groupgoal, spritegoal, turbulence and wander. Here we come up with a simple affector--gravity to continue our experiment.

particlesystem{    anchors.centerIn:parent    imageparticle    {        Source: "Qrc:///particleresources/ Fuzzydot.png "        colorvariation:1.0    }    Emitter    {        emitrate:20        size:10        lifespan:4000        velocity:angledirection        {            magnitude:100            anglevariation:360        }    }    Gravity    {        angle:90        magnitude: +}    }

The demo program is as follows:

As you can see, by specifying the angle of the gravity (falling direction) and the magnitude (falling acceleration), we can control the various parameters of the particles in the operation of the particles.

A variety of particle systems are also used in my indie game, "Take medicine." For example, when the scene switches around 6,000 capsules to the upper-right corner of the 30-degree direction of flight, bacteria and capsules after the elimination of the effects of crushing, as well as the background of the capsule floating empty effects, these are used in the particle effect. In fact, good particle effects can make the player's eyes bright, and can achieve some degree of pleasure.

This article participated in the CSDN Bowen Contest, please support me, vote for me!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.