<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript" language="JavaScript">
//<![CDATA[
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();
}
if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
origWidth = innerWidth;
origHeight = innerHeight;
onresize = reDo;
}
onerror = null;
//]]>
</script>
<style type="text/css">/*<![CDATA[*/
< !-- div.WebHelpPopupMenu {
position: absolute;
left: 0px;
top: 0px;
z-index: 4;
visibility: hidden;
}
p.WebHelpNavBar {
text-align: right;
}
-->
/*]]>*/</style>
<script type="text/javascript">//<![CDATA[
gRootRelPath = "../../../..";
gCommonRootRelPath = "../../../..";
gTopicId = "9.2.5.10";
//]]></script>
<script type="text/javascript" src="../../../../template/scripts/rh.min.js"></script>
<script type="text/javascript" src="../../../../template/scripts/common.min.js"></script>
<script type="text/javascript" src="../../../../template/scripts/topic.min.js"></script>
<script type="text/javascript" src="../../../../template/scripts/topicwidgets.min.js"></script>
<script type="text/javascript" src="../../../../whxdata/projectsettings.js"></script>
<link rel="stylesheet" type="text/css" href="../../../../template/styles/topic.min.css"/>
<link rel="stylesheet" type="text/css" href="../../../../template/Charcoal_Grey/topicheader.css"/>
<meta name="topic-status" content="Draft"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Particles</title>
<meta name="generator" content="Adobe RoboHelp 2019"/>
<link rel="stylesheet" href="../../../../assets/css/default.css" type="text/css"/>
<meta name="rh-authors" content="Mark Alexander"/>
<meta name="topic-comment" content="Reference section for the Particle functions and variables"/>
<meta name="rh-index-keywords" content=""/>
<meta name="search-keywords" content="Particles"/>
</head>
<body>
<div class="topic-header rh-hide" id="rh-topic-header" onclick="rh._.goToFullLayout()">
<div class="logo">
</div>
<div class="nav">
<div class="title" title="Particles">
<span>Particles</span>
</div>
<div class="gotohome" title="Click here to see this page in full context">
<span>Click here to see this page in full context</span>
</div>
</div>
</div>
<div class="topic-header-shadow rh-hide" id="rh-topic-header-shadow"></div>
<!--<div class="body-scroll" style="top: 150px;">-->
<h1>Particles</h1>
<p>For complex things in GameMaker Studio 2 you would normally have an <a href="../../../../The_Asset_Editors/Objects.htm">object</a> and create <a href="../../Asset_Management/Instances/Instances.htm">instances</a> of that object around the room.
However, for graphics effects, this can be expensive as every instance comes with a "cost" in processing due to the variables it contains and the codes it has in the different events. You can reduce this cost by turning to <a href="../../../../The_Asset_Editors/Room_Properties/Layer_Properties.htm">tilemap layers</a> and <a href="../../../../The_Asset_Editors/Room_Properties/Layer_Properties.htm">asset layers</a> for drawing your graphics needs but those are generally static and cannot be changed or moved around much. However, there is one other option for drawing
fast yet versatile graphics effects in your games, and that is to use <i>particles</i>.</p>
<p><strong>Particles </strong>are graphic resources that have certain properties which are defined within a <i>particle system</i>. These properties cannot be manipulated directly for individual particles, but are changed through the code that is used
to define the individual particle and the system that it belongs to. They are very useful for creating beautiful and flashy effects (or subtle and discreet ones!) like explosions, decals, rain, snow, star fields and debris in a game without the CPU
overhead that using instances has.</p>
<p>The basic setup for a particle system follows three steps, with the third step being optional depending on how you wish to create your particle effects within the room:</p>
<ul class="colour">
<li><b>Create a particle system</b>: The particle system is like a container that we will use to hold our different particle types ready for use. We use code to define a series of visual aspects and behaviours for our particles, and then we place them
in the "container" so that we can take them out and use them whenever and wherever we need later.</li>
<li><b>Create particle types</b>: Particle types are the graphic effect itself. You can have many different types, each with their own range of colours, alphas, sizes and movements, but its important to note that you <i>do not have control over individual particles</i>.
You define a series of parameters and the particle will be created to have a random spread of behaviours chosen from them.</li>
<li><b>Create emitters</b>: Emitters are an option that can be used to burst or stream particles from within very clearly defined limits. They are optional because you can create particles from any instance using the <a href="Particle_Systems/part_particles_create.htm"><tt>part_particles_create()</tt></a> and <a href="Particle_Systems/part_particles_create_colour.htm"><tt>part_particles_create_colour()</tt></a> functions but they are not always adequate for every situation.</li>
</ul>
<p>Although particles are an excellent tool for creating effects, they do come with certain restrictions and good practices which need to be followed unless you want your game to suffer from poor performance or even potentially crash:</p>
<ul class="colour">
<li>Particle systems, particles and emitters take up memory and as such you should be very careful how you use them as it is very easy to cause a memory leak which will slow down and eventually crash your game. One way to cope with this is to have a <i>global</i> system with everything defined at the start of the game and removed at the end, but if you want a dynamic system then each particle and emitter (and the system itself) should be destroyed the moment it is not needed.</li>
<li>Particles may be fast and light on the CPU, but they still require <i>some</i> processing and so you shouldn't have 40,000 of them bursting across the screen at a time. Limit them to those that are necessary to achieve a specific effect and no
more.</li>
<li>If you define your own particle sprite instead of using one of the 14 included sprites, you should try to keep them as small as possible to achieve the effect you require.</li>
<li>Particles do <i>not</i> interact with anything. Should you need them to have any type of interaction with the user or any other instances in your game, you should be looking at using instances instead as particles are purely graphic.</li>
<li>Even though there is no technical limit to the amount of systems, emitters and particles you can create in one game, you should try and limit everything to the minimum number possible to keep memory use as low as possible.</li>
<li>On mobile devices, take care with particles as <i>drawing</i> them can be slow if they cover a large area of the screen (over-draw on mobile devices is one of the main causes of slowdown).</li>
<li>With HTML5 there is no additive blending, and unless you have WebGL enabled, you cannot have colour blending either.</li>
</ul>
<p>The easiest way of creating particles in your game with GameMaker Studio 2 is to use the built-in effects mechanism. These effects are created using an internal particle system which is basically a very fast method for drawing graphical effects
only and as such you do not have to worry about all the details (like memory management) when using these functions. You simply specify the type of effect, the position where it must be created, the size you want it to be and finally, its colour then
let GameMaker Studio 2 do all the work.</p>
<p>The following functions exists for creating the built in particle effects:</p>
<p> </p>
<ul class="colour">
<li><a href="effect_create_below.htm">effect_create_below</a></li>
<li><a href="effect_create_above.htm">effect_create_above</a></li>
<li><a href="effect_clear.htm">effect_clear</a></li>
</ul>
<p> </p>
<p>Even though these effects are limited in scope and customisation, they can still be used to create some simple, great effects with very little effort. For example by creating a small puff of grey smoke below a moving missile in each step, a pretty convincing
smoke trail is created, so even when you are an expert in particles it pays to remember that these effects exists as they can still save you some time.</p>
<p>However, the true potential of particles is in desiging and creating your own effects using the powerful functions that the GameMaker Language supplies to you. You can find out more from each of the following sections:</p>
<p> </p>
<ul class="colour">
<li><a href="Particle_Systems/Particle_Systems.htm"><label for="two">Particle Systems</label></a></li>
<li><a href="Particle_Types/Particle_Types.htm"><label for="three">Particle Types</label></a></li>
<li><a href="Particle_Emitters/Particle_Emitters.htm"><label for="four">Particle Emitters</label></a></li>
</ul>
<p> </p>
<p><label for="four">There is also a section that gives you a basic guide on how to design and create particles for your games on the following page:</label></p>
<p> </p>
<ul class="colour">
<li><a href="../../../../Additional_Information/Guide_To_Using_Particles.htm">Guide To Using Particles</a></li>
</ul>
<p> </p>
<p> </p>
<p> </p>
<div class="footer">
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="../Drawing.htm">Drawing</a></div>
<div style="float:right">Next: <a href="../Textures/Textures.htm">Textures</a></div>
</div>
</div>
<h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
</div>
<!-- KEYWORDS
Particles
-->
<!-- TAGS
particle_functions
-->
</body></html>