Skip to content
Snippets Groups Projects
qtquick-particles-imageparticle-example.html 8.72 KiB
Newer Older
  • Learn to ignore specific revisions
  • <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
    <!-- imageparticle.qdoc -->
      <title>Qt Quick Particles Examples - Image Particles | Qt Quick 5.15.0</title>
      <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
      <script type="text/javascript">
        document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
        // loading style sheet breaks anchors that were jumped to before
        // so force jumping to anchor again
        setTimeout(function() {
            var anchor = location.hash;
            // need to jump to different anchor first (e.g. none)
            location.hash = "#";
            setTimeout(function() {
                location.hash = anchor;
            }, 0);
        }, 0);
      </script>
    </head>
    <body>
    <div class="header" id="qtdocheader">
        <div class="main">
        <div class="main-rounded">
            <div class="navigationbar">
            <ul>
    <li><a href="../qtdoc/index.html">Qt 5.15</a></li>
    <li><a href="qtquick-index.html">Qt Quick</a></li>
    <li>Qt Quick Particles Examples - Image Particles</li>
    <li id="buildversion"><a href="qtquick-index.html">Qt 5.15.0 Reference Documentation</a></li>
        </ul>
        </div>
    </div>
    <div class="content">
    <div class="line">
    <div class="content mainContent">
    <div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
    <h1 class="title">Qt Quick Particles Examples - Image Particles</h1>
    <span class="subtitle"></span>
    <!-- $$$particles/imageparticle-brief -->
    <p>This is a collection of examples using Affectors in the QML particle system.</p>
    <!-- @@@particles/imageparticle -->
    <!-- $$$particles/imageparticle-description -->
    <div class="descr"> <a name="details"></a>
    <p class="centerAlign"><img src="images/qml-imageparticle-example.png" alt="" /></p><p>This is a collection of small QML examples relating to using Affectors in the particle system. Each example is a small QML file emphasizing a particular type or feature.</p>
    <p>All at once shows off several of the features of <a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a> at the same time.</p>
    <pre class="qml">
     <span class="name">sprites</span>: [
         <span class="type"><a href="qml-qtquick-sprite.html">Sprite</a></span> {
             <span class="name">name</span>: <span class="string">&quot;bear&quot;</span>
             <span class="name">source</span>: <span class="string">&quot;../../images/bear_tiles.png&quot;</span>
             <span class="name">frameCount</span>: <span class="number">13</span>
             <span class="name">frameDuration</span>: <span class="number">120</span>
         }
     ]
     <span class="name">colorVariation</span>: <span class="number">0.5</span>
     <span class="name">rotationVelocityVariation</span>: <span class="number">360</span>
     <span class="name">colorTable</span>: <span class="string">&quot;../../images/colortable.png&quot;</span>
    </pre>
    <p>Colored shows a simple <a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a> with some color variation.</p>
    <pre class="qml">
     <span class="type"><a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a></span> {
         <span class="name">anchors</span>.fill: <span class="name">parent</span>
         <span class="name">source</span>: <span class="string">&quot;qrc:///particleresources/star.png&quot;</span>
         <span class="name">alpha</span>: <span class="number">0</span>
         <span class="name">alphaVariation</span>: <span class="number">0.2</span>
         <span class="name">colorVariation</span>: <span class="number">1.0</span>
     }
    </pre>
    <p>Color Table sets the color over life on the particles to provide a fixed rainbow effect.</p>
    <pre class="qml">
     <span class="name">source</span>: <span class="string">&quot;qrc:///particleresources/glowdot.png&quot;</span>
     <span class="name">colorTable</span>: <span class="string">&quot;../../images/colortable.png&quot;</span>
     <span class="name">sizeTable</span>: <span class="string">&quot;../../images/colortable.png&quot;</span>
    </pre>
    <p>Deformation spins and squishes a starfish particle.</p>
    <pre class="qml">
     <span class="type"><a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a></span> {
         <span class="name">system</span>: <span class="name">sys</span>
         <span class="name">groups</span>: [<span class="string">&quot;goingLeft&quot;</span>, <span class="string">&quot;goingRight&quot;</span>]
         <span class="name">source</span>: <span class="string">&quot;../../images/starfish_4.png&quot;</span>
         <span class="name">rotation</span>: <span class="number">90</span>
         <span class="name">rotationVelocity</span>: <span class="number">90</span>
         <span class="name">autoRotation</span>: <span class="number">true</span>
     }
     <span class="type"><a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a></span> {
         <span class="name">system</span>: <span class="name">sys</span>
         <span class="name">groups</span>: [<span class="string">&quot;goingDown&quot;</span>]
         <span class="name">source</span>: <span class="string">&quot;../../images/starfish_0.png&quot;</span>
         <span class="name">rotation</span>: <span class="number">180</span>
         <span class="name">yVector</span>: <span class="name">PointDirection</span> { <span class="name">y</span>: <span class="number">0.5</span>; <span class="name">yVariation</span>: <span class="number">0.25</span>; <span class="name">xVariation</span>: <span class="number">0.25</span>; }
     }
    </pre>
    <p>Rotation demonstrates the autoRotate property, so that particles rotate in the direction that they travel.</p>
    <p>Sharing demonstrates what happens when multiple ImageParticles try to render the same particle. The following <a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a> renders the particles inside the <a href="qml-qtquick-listview.html">ListView</a>:</p>
    <pre class="qml">
     <span class="type"><a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a></span> {
         <span class="name">anchors</span>.fill: <span class="name">parent</span>
         <span class="name">system</span>: <span class="name">particles</span>
         <span class="name">source</span>: <span class="string">&quot;../../images/flower.png&quot;</span>
         <span class="name">alpha</span>: <span class="number">0.1</span>
         <span class="name">color</span>: <span class="string">&quot;white&quot;</span>
         <span class="name">rotationVariation</span>: <span class="number">180</span>
         <span class="name">z</span>: -<span class="number">1</span>
     }
    </pre>
    <p>The following <a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a> is placed inside the list highlight, and renders the particles above the other <a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a>.</p>
    <pre class="qml">
     <span class="type"><a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a></span> {
         <span class="name">anchors</span>.fill: <span class="name">parent</span>
         <span class="name">system</span>: <span class="name">particles</span>
         <span class="name">source</span>: <span class="string">&quot;../../images/flower.png&quot;</span>
         <span class="name">color</span>: <span class="string">&quot;red&quot;</span>
         <span class="name">clip</span>: <span class="number">true</span>
         <span class="name">alpha</span>: <span class="number">1.0</span>
     }
    </pre>
    <p>Note that because it sets the color and alpha in this <a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a>, it renders the particles in a different color. Since it doesn't specify anything about the rotation, it shares the rotation with the other <a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a> so that the flowers are rotated the same way in both. Note that you can undo rotation in another <a href="qml-qtquick-particles-imageparticle.html">ImageParticle</a>, you just need to explicitly set rotationVariation to 0.</p>
    <p>Sprites demonstrates using an image particle to render animated sprites instead of static images for each particle.</p>
    <p><a href="https://code.qt.io/cgit/qt/qtdeclarative.git/tree/examples/quick/particles/imageparticle?h=5.15">Example project @ code.qt.io</a></p>
    </div>
    <!-- @@@particles/imageparticle -->
            </div>
           </div>
       </div>
       </div>
    </div>
    <div class="footer">
       <p>
       <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
       Documentation contributions included herein are the copyrights of
       their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
       of their respective owners. </p>
    </div>
    </body>
    </html>