Multiple particles movement. Is it possible to keep 30 FPS?

I'm adding some procedural-generated animation to my game and encountered problems with FPS.

Here is the ready-to-launch main.lua file that demonstrates the code that causes the problem.

It does exactly what is happening in this GIF. Human-shaped figures crumble into particles that are forced by gravity. The GIF is recorded from simulator so there is stable 30 FPS.

Figures crumble

These figures consist of ~40 pieces each and each figure calculates the positions of its particles separately. Everything works fine on my Mac but in the real Playdate device, I see degradation of FPS during this process. It's fine when I have only 1-2 but it slows down starting from 3 figures.

I've made several optimizations:

  • removed colliders from particles and used simple custom logic
  • use simple variables instead of points and vectors
  • each figure calculates its pieces (so particles themselves are "dumb")
  • to ensure that the problem is not in creating the objects I have them already created and check only the "animation".

Ideally, I would like to have some random initial speeds for each particle in each figure.
So I have 5 * 40 ~ 200 simultaneously and independently moving objects. Is it even possible with Playdate's hardware?

Thank you in advance!

1 Like

I think it should be possible -- I'm writing half my game in C, and that's a lot faster.

Let's leave aside that hornets' nest though, and focus on your current code.

I think the problem here is mainly that sprites are a bit too heavyweight for this (maybe?); I'd probably use a bitmap (for an entire figure) or something. Then also find a way to remove most state out of the particles, so you could make a cellular automata.

Anyway, keeping your current idea/structure largely untouched, and just removing the dependencies on the sprite-system (with a few other hacks ... not sure how much those contribute though), already seems to double the performance; see Playdate crumbling figures · GitHub

(The use of timers didn't seem to slow it down, that's a good to know also.)

Thank you!
I'm pretty new to Playdate SDK and do not have much understanding between sprites and other means of drawing objects.
Thank you for example gist. With 10 figures presented it still causes some visible degradation in FPS but I hope I'll need no more than 5 simultaneous animations.

1 Like


That's a lot.

But you can compare to an implementation using pdParticles - Playdate particle system