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. That is, they can be built in whatever graphical display module a Qobject object does not have to rely on QT. Take a sample to say it. Suppose you want to achieve a smooth transition of the background music, you can not write extra code. Animating the volume of the background music can be achieved with an animated interpolation. In fact, I made the game "take medicine" is the effect of such realization.

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 were able to use the particle system to produce very powerful effects, although the official sample only had 2D of particles, but we were able to customize the vertex shader and fragment shader to support 3D sample 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    height: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: "qrc:/// Particleresources/fuzzydot.png "            colorvariation:1.0        }        Emitter        {            emitrate:20            size: Ten            lifespan:4000            velocity:angledirection            {                magnitude: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 demo program above we can tell that a particle system is basically made up of Particlesystem, imageparticle, and emitter. The Particlesystem is indispensable, as this is the necessary type to control the components of each particle system. Assuming that 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 indispensable class, and its role is to specify how these samples 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 adopt Particlepainter other sub-class 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, beyond the three, there is another class that cannot be ignored. That's affector. In general, particles will maintain their initial velocity, acceleration, and size after emitter action, and these values are no longer controlled by emitter, only affector ability to control the size of the particle during execution.

Here Affector is just a base class, and on its basis there are a lot of subclasses defined based on different effects. For example, 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 following are examples of demo programs:

You can see that by specifying the angle of the gravity (falling direction) and the magnitude (falling acceleration), we are able to control the various parameters of the particles in the particle execution.

A variety of particle systems are also used in my indie game, "Take medicine." Let's say there are about 6,000 capsules flying in the 30-degree direction of the upper right corner when the scene switches. After the bacteria and capsules are removed, the effects of smashing will appear, as well as the effects of floating capsules in the background. These all use the particle effect.

In fact, good particle effects can make the player's eyes bright. can also achieve some degree of pleasure.

This article participates in the CSDN Bowen Contest, please support me. Cast a vote for me!

QT Mobile Application Development (IV): applying particle effects

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.