Basics#
Particle#
There are a lot of arguments, but required is only center position. So this is the minimal particle example
# Import pygame and particles
import pygame
from pygame_particles import Particle
# Initialize screen
pygame.init()
screen = pygame.display.set_mode((300, 300))
# Creates standart particle on (100, 100) position
my_cool_particle = Particle(150, 150)
# Update it if you want
# my_cool_particle.update()
# Draw it
my_cool_particle.draw(screen)
# Update display
pygame.display.flip()
By running this code you won’t see something nice and interesting, it is just a showcase of how to use them
Shape#
You can subclass shape object to create your own
from pygame_particles import Shape
class CustomShape(Shape):
def __init__(self, center, radius, speed):
super().__init__(center, [(-10, 0), (0, -10), (10, 0), (0, 10)], speed)
Now you can use this CustomShape as shape_cls argument for particle
Container#
Container is an object which has some methods to make your work easier
from pygame_particles import ParticleContainer
screen = ... # pygame.Surface
particle = ... # Particle
# Creating container. It will store copies of particles. You can make it empty at the beginning
container = ParticleContainer(particle, particle, particle)
# Add particle to the container (also copies)
container.add(particle)
# Updates all particles, draw them and deletes dead particles, so they don't take your memory
container.draw(screen)
Random in range#
Particle’s speed and size can be a single number or a tuple.
3 # Just 3
3.5 # Just 3.5
(1, 3) # A random integer value in range [1, 3]
(1, 3.5) # A random float value in range [1, 3.5]