⭐️ In this tutorial we will learn how to create visuals by updating a bunch of particles~
Fireworks by Trasevol_Dog (@URL)
Hello Table
In order to create particles we need to learn about tables.
Tables are like lists that you can add and remove stuff from. They are defined using curly brackets. They are similar to arrays in other programming languages. Note that Lua arrays are 1-based by default, not 0-based. FOREACH starts at TBL[1], not TBL[0].
For example we can have a table of numbers and loop through them using all
:
Tables can also be used to store fields. These are just named values that you can reference.
For example we can store some values in a table and then use them to draw a circle:
Hello Particles
Ok now that we know about tables, let’s make some particles dance!
Rain
Let’s try to get a rain effect by making particles move from the top of the screen to the bottom.
We are going to have particles that have position, velocity, color, size and time:
We will then have a function that updates our particle by changing its position based on the velocity and deletes the particles when it passes the bottom of the screen:
Lastly we will have a function that draws our particle, in this case we’ll represent it as a circle:
Now let’s put these functions into update and draw to get things going. We will create a particle each update at the top of the screen:
If you put all this code together you should get something like this:
Burst
Alternatively we could move the particles outwards to create a burst effect:
Create:
Update:
Draw and update:
Result:
You can load the code into pico-8-edu using this URL.
Exercise 🍓
Try messing around with the variables to see how the particles change. Can you get a different effect by changing how the particles behave?
Next
Appendix
Resources