-
Notifications
You must be signed in to change notification settings - Fork 2
Particle Effects
Particle effects are supported natively by some very useful aspects of LibGDX. Some good resources are listed at the bottom.
There are
- Create a particle effect file using the LibGDX 2D Particle Editor. (See Using the editor).
- Add the particle effect file and particle image to
2021-studio-1/source/core/assets/...
so that they can be loaded. Ensure the particle image is made into a .atlas file with something like the GDX Texture packer. - Open the effect file:
FileHandle effectData = Gdx.files.internal("pathToFile")
(ResourceService
cannot handleFileHandle
s) - Open the particle image as an atlas:
TextureAtlas textureAtlas = ServiceLocator.getResourceService("pathToAtlas")
- Load the particle effect with
particleEffect = new ParticleEffect();
andparticleEffect.load(effectData, textureAtlas);
- This works best in game when loaded into a component to follow the entity-component design pattern. In the component's
render(SpriteBatch batch)
method, put the following lines:
particleEffect.setPosition(entity.getPosition().x, entity.getPosition().y);
particleEffect.update(Gdx.graphics.getDeltaTime());
particleEffect.draw(batch);
- To start the particle emission, call
particleEffect.start()
and it will start. Depending on whether you set continuous to true or false in the Particle Editor, this may play continuously or just once.
See ParticleEffectRenderComponent
for an example.
That is the process. I have tried to mirror the Factory design pattern by using the ObstacleFactory
, I didn't think particles deserved their own factory since at the moment there is only one particle effect. I have also tried to follow the Service Locator design pattern by keeping ServiceLocator
's ResourceService
functionality, but I found that AssetManager
in LibGDX does not handle the FileHandle
that the effect data is kept in, so effect data is loaded without the ResourceManager
.
I found it only worked when I cloned LibGDX source, opened the run.gradle file in Intillej and followed the third method here. Make sure to run ./gradlew fetchNatives
in the repo's directory from terminal like is specified here.
In terms of actually creating the particle effects, these tutorials go over it far better than I could. The editor uses particle images as .png files, so just make sure to pack into an atlas and use that in game.
This component plays the given particle effect when the correct thing collides with it. The required arguments are effectData
, textureAtlas
, and targetLayer
. Note that it scales the particle effect by a 0.02 multiple because the particles are initially very large.
effectData
: This is the particle effect data file saved with the Particle Editor and opened in game as a FileHandle
using Gdx.files.internal("pathToFile")
. ResourceManager
does not seem to be able to handle FileHandle
s. It is the information telling the game how to play the effect.
textureAtlas
: This is the image each particle will look like. Must be a fully white, probably small image packed into an atlas file and opened using the resource manager: ServiceLocator.getResourceService().getAsset("pathToAtlas", TextureAtlas.class)
targetLayer
: On collision with this component, if the colliding entity has PhysicsLayer
equal to targetLayer
, the component will play the effect.
So, an example particle effect is given by ObstacleFactory.createWallParticles
:
public static Entity createWallParticles(String particleEffectPath, String particleAtlasPath) {
FileHandle effectData = Gdx.files.internal("particles/rainbow_spread_2");
TextureAtlas particleImage = ServiceLocator.getResourceService()
.getAsset("particles/particles.atlas", TextureAtlas.class);
return new Entity()
.addComponent(new PhysicsComponent())
.addComponent(new HitboxComponent())
.addComponent(new ParticleEffectRenderComponent(effectData, particleImage,
PhysicsLayer.PLAYER));
}
LibGDX Wiki: Particle Editor and making effects
Welcome to the Ragnarok Racer docs: authors: jeffery, amboogle, mwah dwaw a wa, dhooma georigie, and georgio, the snake hisses --ahh! your venomous gaze! the weary traveler cries
Graphical Design
User Testing
Sound and Music
Code Design / Documentation
Technical Aspects
- Collision Boxes and Entity Collisions
- Player Character Technical Aspects
- Wall of Death Technical Aspects
- Camera Shaking and Wall of Death Intensification Aspects
- Wall of Death Variable Speed Aspects
- Power Ups Technical Aspects
- Loading levels
- AI Tasks and Movements
- Particle effects
- Enemy, Obstacles & Projectiles Technical Aspects