How to create the effect of rain?
How to create the effect of cloud across the map?
Note: If using Particle possible!
Below is the full code that generates these particles on the screen.
Did you do the rainfall and cloud moving horizontally alert Particle if possible.
Otherwise what would be another outlet for this problem?
package project.parallax;
import project.parallax.actor.Hero;
import box2dLight.PointLight;
import box2dLight.RayHandler;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEmitter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Array;
public class LightRenderer {
private RayHandler rayHandler;
private OrthographicCamera camera;
private PointLight playerLight;
private Hero player;
private ParticleEffect effect;
private Vector2 positionLight = new Vector2();
private BodyDef tileBodyDef;
private World lightWorld;
private FixtureDef fixtureDef;
private PolygonShape tileShape;
public LightRenderer(OrthographicCamera camera, Hero player) {
this.camera = camera;
this.player = player;
lightWorld = new com.badlogic.gdx.physics.box2d.World(new Vector2(), true);
RayHandler.useDiffuseLight(true);
this.rayHandler = new RayHandler(lightWorld);
this.rayHandler.setCombinedMatrix(this.camera.combined);
int distanceLight = 96;
playerLight = new PointLight(rayHandler, 128, new Color(0.8f,0.8f,0.8f,0.6f), distanceLight, 510, 385);
// Create a shape that casts a shadow
PolygonShape tileShape = new PolygonShape();
tileShape.setAsBox(5.5f, 5.5f);
tileBodyDef = new BodyDef();
tileBodyDef.type = BodyType.StaticBody;
fixtureDef = new FixtureDef();
fixtureDef.shape = tileShape;
fixtureDef.filter.groupIndex = 0;
tileBodyDef.position.set(510, 385);
effect = new ParticleEffect();
effect.load(Gdx.files.internal("data/test.p"),Gdx.files.internal("data/"));
Array<ParticleEmitter> emitters = new Array<ParticleEmitter>(effect.getEmitters());
effect.getEmitters().clear();
effect.getEmitters().add(emitters.get(3));
effect.start();
//tileShape.dispose();
}
SpriteBatch sb = new SpriteBatch();
public void drawBlasts(){
effect.setPosition(300, 300);
sb.begin();
effect.draw(sb, Gdx.app.getGraphics().getDeltaTime());
sb.end();
}
/**
* Cria uma so~mbra,como se estivesse segurando uma vela.
*/
public void addEffectShadow(){
Body tileBody = lightWorld.createBody(tileBodyDef);
tileBody.createFixture(fixtureDef);
}
public void setAmbient(Color color) {
this.rayHandler.setAmbientLight(color);
}
public void render() {
this.positionLight.set(this.player.getX(), this.player.getY());
this.playerLight.setPosition(positionLight);
this.rayHandler.setCombinedMatrix(this.camera.combined);
this.rayHandler.updateAndRender();
}
public void dispose() {
rayHandler.dispose();
tileShape.dispose();
}
public PointLight getPlayerLight() {
return playerLight;
}
public void setPlayerLight(PointLight playerLight) {
this.playerLight = playerLight;
}
}
Test.p
smoke
- Delay -
active: false
- Duration -
lowMin: 1.0
lowMax: 1.0
- Count -
min: 0
max: 1000
- Emission -
lowMin: 0.0
lowMax: 0.0
highMin: 3.0
highMax: 3.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Life -
lowMin: 0.0
lowMax: 0.0
highMin: 3000.0
highMax: 3000.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Life Offset -
active: false
- X Offset -
active: false
- Y Offset -
active: false
- Spawn Shape -
shape: square
- Spawn Width -
lowMin: 0.0
lowMax: 0.0
highMin: 180.0
highMax: 800.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Spawn Height -
lowMin: 0.0
lowMax: 0.0
highMin: 110.0
highMax: 6000.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Scale -
lowMin: 0.0
lowMax: 0.0
highMin: 256.0
highMax: 256.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Velocity -
active: true
lowMin: -25.0
lowMax: -25.0
highMin: 25.0
highMax: 25.0
relative: false
scalingCount: 2
scaling0: 0.0
scaling1: 1.0
timelineCount: 2
timeline0: 0.0
timeline1: 1.0
- Angle -
active: true
lowMin: 0.0
lowMax: 0.0
highMin: 1.0
highMax: 360.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Rotation -
active: true
lowMin: 1.0
lowMax: 360.0
highMin: -30.0
highMax: 30.0
relative: true
scalingCount: 2
scaling0: 0.0
scaling1: 1.0
timelineCount: 2
timeline0: 0.0
timeline1: 1.0
- Wind -
active: false
- Gravity -
active: false
- Tint -
colorsCount: 6
colors0: 1.0
colors1: 0.0
colors2: 0.0
colors3: 1.0
colors4: 0.9843137
colors5: 0.0
timelineCount: 2
timeline0: 0.0
timeline1: 1.0
- Transparency -
lowMin: 0.0
lowMax: 0.0
highMin: 1.0
highMax: 1.0
relative: false
scalingCount: 3
scaling0: 0.0
scaling1: 0.49122807
scaling2: 0.0
timelineCount: 3
timeline0: 0.0
timeline1: 0.5068493
timeline2: 1.0
- Options -
attached: false
continuous: true
aligned: false
additive: true
behind: false
- Image Path -
particle-cloud.png
effect rain: