Pen Particles

Материал из Поле цифровой дидактики

Шаблон:Stub

This tutorial will show how to make pen particles. These are often used as background or death effects in many games.

Adding Particles to a List

The first step to making pen particles is making a list of particles as a 2D array, each particle will have more than one item on the particles list. First, a list needs to be created, called particles:

particles

Now, a script that adds a particle at a certain x and y position with a certain x and y velocity.

defineAddparticle|Position:x,y|Velocities:XVelYVelColor:colorSizesizeaddxtoparticlesThestartingXpositionoftheparticleaddytoparticlesThestartingYpositionoftheparticleaddXveltoparticlesThestartingXvelocityoftheparticleaddYveltoparticlesThestartingYvelocityoftheparticleaddcolortoparticlesThecoloroftheparticleaddsizetoparticlesThesizeoftheparticle

Deleting Particles

Now a script needs to be created to delete a particle at a certain item on the particles list:

defineDeleteparticleideletei+5ofparticlesstartsattheparticle'slastiteminthelistdeletei+4ofparticlesandmovesbackuntilallitemsonthelistthatbelongtothatparticlearedeleteddeletei+3ofparticlesdeletei+2ofparticlesdeletei+1ofparticlesdeleteiofparticles

Rendering Particles

A script will also be needed to render the particles that are already stored in the particles list:

defineRendereraseallerasingallofthedrawingmadepreviouslysetito1repeatlengthofparticles/6Theamountofparticlesinthelistbecauseeachparticletakesup6itemsgotox:itemiofparticlesy:itemi+1ofparticlesThistutorialusestheparticle'sitemsonthelisttosetthepropertiesofthespritesetpensizetoitemi+5ofparticlessetpencolortoitemi+4ofparticlespendownMakingadotpenupchangeiby6

Updating the Particles' Positions

This script moves the particles around:

defineUpdatesetito1repeatlengthofpaticles/6replaceitemiofparticleswithitemiofparticles+itemi+2ofparticlesreplaceitemi+1ofparticleswithitemi+1ofparticles+itemi+3ofparticlesChangingtheypositionoftheparticlebyitsyvelocityreplaceitemi+2ofparticleswithitemi+2ofparticles-1Optionalgravity,changetheYvelocityby-1ifabsitemiofparticles>240orabsitemi+1ofparticles>180thenDeleteparticleiiftheparticleifoffthescreen,deleteit.endchangeiby6

Implementing The Code

Now that all the scripts are made, they must be used. Depending on the type of program wished to make, one may want to make mouse effects:

whenclickeddeleteallofparticlesforeverAddparticle|Position:mousex,mousey|Velocities:pickarandom-10to10pickarandom-10to10Color:pickarandom0to100Sizepickarandom-10to10UpdateRenderend

Or one can make background effects:

whenclickedIfbackgroundeffectsaremade,makesurethattheydonothavegravitybyremovingthechangeyvelocityblockintheupdatescript.deleteallofparticlesforeverAddparticle|Position:pickarandom-240to240,pickarandom-180to180|Velocities:pickarandom-10to10pickarandom-10to10Color:pickarandom0to100Sizepickarandom-10to10UpdateRenderend