treasurehunting2/PySDL2-0.9.5/doc/html/modules/sdl2ext_particles.html

233 lines
14 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>sdl2.ext.particles - A simple particle system &#8212; PySDL2 0.9.5 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.9.5',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
<link rel="next" title="2D and 3D direct pixel access" href="sdl2ext_pixelaccess.html" />
<link rel="prev" title="Image loaders" href="sdl2ext_image.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="sdl2ext_pixelaccess.html" title="2D and 3D direct pixel access"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="sdl2ext_image.html" title="Image loaders"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<span class="target" id="module-sdl2.ext.particles"></span><div class="section" id="sdl2-ext-particles-a-simple-particle-system">
<h1>sdl2.ext.particles - A simple particle system<a class="headerlink" href="#sdl2-ext-particles-a-simple-particle-system" title="Permalink to this headline"></a></h1>
<dl class="class">
<dt id="sdl2.ext.particles.ParticleEngine">
<em class="property">class </em><code class="descclassname">sdl2.ext.particles.</code><code class="descname">ParticleEngine</code><a class="headerlink" href="#sdl2.ext.particles.ParticleEngine" title="Permalink to this definition"></a></dt>
<dd><p>A simple particle processing system. The <a class="reference internal" href="#sdl2.ext.particles.ParticleEngine" title="sdl2.ext.particles.ParticleEngine"><code class="xref py py-class docutils literal"><span class="pre">ParticleEngine</span></code></a>
takes care of creating, updating and deleting particles via callback
functions. It only decreases the life of the particles by itself and
marks them as dead, once the particle&#8217;s life attribute has reached 0
or below.</p>
<dl class="attribute">
<dt id="sdl2.ext.particles.ParticleEngine.createfunc">
<code class="descname">createfunc</code><a class="headerlink" href="#sdl2.ext.particles.ParticleEngine.createfunc" title="Permalink to this definition"></a></dt>
<dd><p>Function for creating new particles. The function needs to take
two arguments, the <code class="docutils literal"><span class="pre">world</span></code> argument passed to <a class="reference internal" href="#sdl2.ext.particles.ParticleEngine.process" title="sdl2.ext.particles.ParticleEngine.process"><code class="xref py py-meth docutils literal"><span class="pre">process()</span></code></a>
and a list of the particles considered dead (<a class="reference internal" href="#sdl2.ext.particles.Particle.life" title="sdl2.ext.particles.Particle.life"><code class="xref py py-attr docutils literal"><span class="pre">Particle.life</span></code></a>
&lt;= 0).</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">creation_func</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">deadparticles</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.particles.ParticleEngine.updatefunc">
<code class="descname">updatefunc</code><a class="headerlink" href="#sdl2.ext.particles.ParticleEngine.updatefunc" title="Permalink to this definition"></a></dt>
<dd><p>Function for updating existing, living particles. The function
needs to take two arguments, the <code class="docutils literal"><span class="pre">world</span></code> argument passed to
<a class="reference internal" href="#sdl2.ext.particles.ParticleEngine.process" title="sdl2.ext.particles.ParticleEngine.process"><code class="xref py py-meth docutils literal"><span class="pre">process()</span></code></a> and a <a class="reference external" href="http://docs.python.org/library/stdtypes.html#set" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">set</span></code></a> of the still living
particles.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">update_func</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">livingparticles</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.particles.ParticleEngine.deletefunc">
<code class="descname">deletefunc</code><a class="headerlink" href="#sdl2.ext.particles.ParticleEngine.deletefunc" title="Permalink to this definition"></a></dt>
<dd><p>Function for deleting dead particles. The function needs to take
two arguments, the <code class="docutils literal"><span class="pre">world</span></code> argument passed to <a class="reference internal" href="#sdl2.ext.particles.ParticleEngine.process" title="sdl2.ext.particles.ParticleEngine.process"><code class="xref py py-meth docutils literal"><span class="pre">process()</span></code></a>
and a list of the particles considered dead (<a class="reference internal" href="#sdl2.ext.particles.Particle.life" title="sdl2.ext.particles.Particle.life"><code class="xref py py-attr docutils literal"><span class="pre">Particle.life</span></code></a>
&lt;= 0).</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">deletion_func</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">deadparticles</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="sdl2.ext.particles.ParticleEngine.process">
<code class="descname">process</code><span class="sig-paren">(</span><em>world : World</em>, <em>components : iterable</em><span class="sig-paren">)</span> &rarr; None<a class="headerlink" href="#sdl2.ext.particles.ParticleEngine.process" title="Permalink to this definition"></a></dt>
<dd><p>Processes all particle components, decreasing their life by 1.</p>
<p>Once the life of all particle components has been decreased
properly and the particles considered dead (life &lt;= 0) are
identified, the creation, update and deletion callbacks are
invoked.</p>
<p>The creation callback takes the passed world as first and the
list of dead particles as second argument.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">particle_createfunc</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">list_of_dead_ones</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
<p>Afterwards the still living particles are passed to the update
callback, which also take the passed world as first and the
living particles as set as second argument.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">particle_updatefunc</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">set_of_living_ones</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
<p>Finally, the dead particles need to be deleted in some way or
another, which is done by the deletion callback, taking the
passed world as first and the list of dead particles as second
argument.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">particle_deletefunc</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">list_of_dead_ones</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="sdl2.ext.particles.Particle">
<em class="property">class </em><code class="descclassname">sdl2.ext.particles.</code><code class="descname">Particle</code><span class="sig-paren">(</span><em>x</em>, <em>y</em>, <em>life : int</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.particles.Particle" title="Permalink to this definition"></a></dt>
<dd><p>A simple particle component type. It only contains information about
a x- and y-coordinate and its current life time. The life time will
be decreased by 1, every time the particle is processed by the
<a class="reference internal" href="#sdl2.ext.particles.ParticleEngine" title="sdl2.ext.particles.ParticleEngine"><code class="xref py py-class docutils literal"><span class="pre">ParticleEngine</span></code></a>.</p>
<dl class="attribute">
<dt id="sdl2.ext.particles.Particle.x">
<code class="descname">x</code><a class="headerlink" href="#sdl2.ext.particles.Particle.x" title="Permalink to this definition"></a></dt>
<dd><p>The x coordinate of the particle.</p>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.particles.Particle.y">
<code class="descname">y</code><a class="headerlink" href="#sdl2.ext.particles.Particle.y" title="Permalink to this definition"></a></dt>
<dd><p>The y coordinate of the particle.</p>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.particles.Particle.life">
<code class="descname">life</code><a class="headerlink" href="#sdl2.ext.particles.Particle.life" title="Permalink to this definition"></a></dt>
<dd><p>The remaining life time of the particle.</p>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.particles.Particle.position">
<code class="descname">position</code><a class="headerlink" href="#sdl2.ext.particles.Particle.position" title="Permalink to this definition"></a></dt>
<dd><p>The x- and y-coordinate of the particle as tuple.</p>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="sdl2ext_image.html"
title="previous chapter">Image loaders</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="sdl2ext_pixelaccess.html"
title="next chapter">2D and 3D direct pixel access</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/sdl2ext_particles.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="sdl2ext_pixelaccess.html" title="2D and 3D direct pixel access"
>next</a> |</li>
<li class="right" >
<a href="sdl2ext_image.html" title="Image loaders"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2013-2016, Marcus von Appen.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
</div>
</body>
</html>