{"id":36,"date":"2019-03-08T10:21:51","date_gmt":"2019-03-08T10:21:51","guid":{"rendered":"http:\/\/www.aquietspace.org\/aqs\/?p=36"},"modified":"2019-03-15T19:48:38","modified_gmt":"2019-03-15T19:48:38","slug":"particlecandy-quick-start-guide","status":"publish","type":"post","link":"https:\/\/www.aquietspace.org\/aqs\/2019\/03\/08\/particlecandy-quick-start-guide\/","title":{"rendered":"ParticleCandy Quick Start Guide"},"content":{"rendered":"<div class='stb-container stb-style-alert stb-caption-box stb-no-caption'><div class='stb-caption'><div class='stb-logo'><img class='stb-logo__image' src='http:\/\/www.aquietspace.org\/aqs\/wp-content\/plugins\/wp-special-textboxes\/themes\/stb-dark\/alert.png' alt='img'\/><\/div><div class='stb-caption-content'>Disclaimer<\/div><div class='stb-tool'><\/div><\/div><div class='stb-content'>The details contained on this page are the copyright of www.x-pressive.com<br \/>\nThey are duplicated here purely for my own personal use as a licensed user of Particle Candy. &nbsp;I cannot and will not provide the code for ParticleCandy so please do not ask. &nbsp;If you wish to try it out please head over to <a href=\"http:\/\/www.x-pressive.com\/ParticleCandy_Corona\/index.html\">www.x-pressive.com<\/a><\/div><\/div>\n<h3>Include the library<\/h3>\n<p>Place the library&#8217;s .lua file in the directory of your project and include it with the following command (just place the name of the library within the quotes, without the &#8220;.lua&#8221; extension) :<\/p>\n<pre class=\"lang:lua decode:true\">local Particles = require(\"lib_particle_candy\")\n\n<\/pre>\n<p>Now create some emitters. Emitters can be created and deleted at any time, but it&#8217;s a good practice to create them right before your scene starts, re-use them during the game and delete them during scene clean-up:<\/p>\n<pre class=\"lang:lua decode:true\">Particles.CreateEmitter(\"name\", x,y, rotation, visible, loop, autoDestroy)\n\n<\/pre>\n<p>You can also receive a handle to the created emitter. This handle can then be used to freely position, rotate or move the emitter. An emitter&#8217;s handle can be used like any common graphics object. Therefore, you can also place an emitter within a certain group. Principally, all particles of an emitter will be drawn inside the emitter&#8217;s parent. So if you put the emitter into a display group, it&#8217;s particles will be drawn inside this group only.<br \/>\n<b>Important note: &nbsp;<\/b>If you store an emitter&#8217;s handle, you must set this reference to the emitter to &#8220;nil&#8221; before you delete the emitter. Otherwise, it cannot be garbage collected and will remain in memory! So be careful when storing emitter handles on your own!<\/p>\n<pre class=\"tab-size:2 whitespace-after:1 lang:lua decode:true \">local MyEmitter = Particles.GetEmitter(\"name\")\n\nMyEmitter.x\t\t= 50\nMyEmitter.y\t\t= 150\nMyEmitter.rotation \t= 180\nMyEmitter.alpha\t\t= 0.5\n\n<\/pre>\n<h3>Creating a particle type<\/h3>\n<p>A particle type describes how particles behave, so a particle type contains all relevant properties of a certain kind of particle. You can create as many different particle types and attach as many of them to an emitter as you like. For a fire effect, for example, you would create one particle type for the smoke, another one for the flames and maybe a third one to show some sparks flying around. Attach them to an emitter then and you are ready to go.<\/p>\n<pre class=\"tab-size:2 whitespace-after:1 lang:lua decode:true\">-- DEFINE PARTICLE TYPE PROPERTIES\nlocal Properties \t\t= {}\nProperties.imagePath\t\t= \"arrow.png\"\nProperties.imageWidth\t\t= 32\nProperties.imageHeight\t\t= 32\nProperties.velocityStart\t= 150\nProperties.autoOrientation\t= true\nProperties.killOutsideScreen\t= true\nProperties.lifeTime\t\t= 3000\nProperties.alphaStart\t\t= 0\nProperties.fadeInSpeed\t\t= 0.5\nProperties.fadeOutSpeed\t\t= -0.75\nProperties.fadeOutDelay\t\t= 1500\n\n-- CREATE THE ACTUAL PARTICLE TYPE\nParticles.CreateParticleType (\"MyParticleType1\", Properties)\n\n-- WE DON'T NEED THIS ANYMORE\nProperties = nil\n\n<\/pre>\n<h3>Attaching the particle types to the emitter<\/h3>\n<p>Now we feed the emitters with the particle types you just created. You can attach as many particle types to an emitter as you like and define an emission rate, emission duration and a delay for each attached particle type (repeat this with each particle type you&#8217;d like to attach to the emitter):<\/p>\n<pre class=\"tab-size:2 whitespace-after:1 lang:lua decode:true\">Particles.AttachParticleType(\"emitter\", \"particleName\", emissionRate, duration, delay)<\/pre>\n<h3>Trigger the emitter<\/h3>\n<p>Now your emitters are charged and can be triggered (or stopped) at any time within the game. The particles will be drawn in the emitter&#8217;s parent group (if there is one) and will be shot in the direction where the emitter points (remember, you can freely move and rotate the emitter -you can also attach it to the exhaust of your space ship, for example).<\/p>\n<pre class=\"lang:lua decode:true \">Particles.StartEmitter(\"name\")<\/pre>\n<p><b>Important note: &nbsp;<\/b>In order to update and animate your particles, don&#8217;t forget to call the library&#8217;s Update() function once every frame (within your main loop).<\/p>\n<pre class=\"lang:lua decode:true\">function mainLoop()\n\t-- TO UPDATE \/ ANIMATE PARTICLES:\n\tParticles.Update()\n\n\t-- Your enterFrame CODE HERE:\n\t-- ...\nend<\/pre>\n<h3>Cleanup<\/h3>\n<p>After your main game loop finished, simply remove all created emitters, particle types and particles on screen by using:<\/p>\n<pre class=\"lang:lua decode:true \">Particles.cleanUp()<\/pre>\n<p><b>Important note: &nbsp;<\/b>If you stored any emitter handles using GetEmitter() you must set these references to the emitters to &#8220;nil&#8221; before you delete the emitters otherwise they cannot be garbage collected and will remain in memory, so be careful when storing emitter handles on your own.<\/p>\n<p>&nbsp;<\/p>\n<p>And this concludes the quick start guide.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Include the library Place the library&#8217;s .lua file in the directory of your project and include it with the following command (just place the name of the library within the quotes, without the &#8220;.lua&#8221; extension) : local Particles = require(&#8220;lib_particle_candy&#8221;) Now create some emitters. Emitters can be created and deleted at any time, but it&#8217;s a good practice to create them right before your scene starts, re-use them during the game and delete them during scene clean-up: Particles.CreateEmitter(&#8220;name&#8221;, x,y, rotation,&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.aquietspace.org\/aqs\/2019\/03\/08\/particlecandy-quick-start-guide\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,4],"tags":[7,6,10,8,9],"_links":{"self":[{"href":"https:\/\/www.aquietspace.org\/aqs\/wp-json\/wp\/v2\/posts\/36"}],"collection":[{"href":"https:\/\/www.aquietspace.org\/aqs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aquietspace.org\/aqs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aquietspace.org\/aqs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aquietspace.org\/aqs\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":13,"href":"https:\/\/www.aquietspace.org\/aqs\/wp-json\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":194,"href":"https:\/\/www.aquietspace.org\/aqs\/wp-json\/wp\/v2\/posts\/36\/revisions\/194"}],"wp:attachment":[{"href":"https:\/\/www.aquietspace.org\/aqs\/wp-json\/wp\/v2\/media?parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aquietspace.org\/aqs\/wp-json\/wp\/v2\/categories?post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aquietspace.org\/aqs\/wp-json\/wp\/v2\/tags?post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}