use of com.badlogic.gdx.graphics.g2d.ParticleEmitter in project libgdx by libgdx.
the class ParticleEmitterTest method create.
@Override
public void create() {
spriteBatch = new SpriteBatch();
effect = new ParticleEffect();
effect.load(Gdx.files.internal("data/test.p"), Gdx.files.internal("data"));
effect.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
// Of course, a ParticleEffect is normally just used, without messing around with its emitters.
emitters = new Array(effect.getEmitters());
effect.getEmitters().clear();
effect.getEmitters().add(emitters.get(0));
inputProcessor = new InputProcessor() {
public boolean touchUp(int x, int y, int pointer, int button) {
return false;
}
public boolean touchDragged(int x, int y, int pointer) {
effect.setPosition(x, Gdx.graphics.getHeight() - y);
return false;
}
public boolean touchDown(int x, int y, int pointer, int newParam) {
// effect.setPosition(x, Gdx.graphics.getHeight() - y);
ParticleEmitter emitter = emitters.get(emitterIndex);
particleCount += 100;
System.out.println(particleCount);
particleCount = Math.max(0, particleCount);
if (particleCount > emitter.getMaxParticleCount())
emitter.setMaxParticleCount(particleCount * 2);
emitter.getEmission().setHigh(particleCount / emitter.getLife().getHighMax() * 1000);
effect.getEmitters().clear();
effect.getEmitters().add(emitter);
return false;
}
public boolean keyUp(int keycode) {
return false;
}
public boolean keyTyped(char character) {
return false;
}
public boolean keyDown(int keycode) {
ParticleEmitter emitter = emitters.get(emitterIndex);
if (keycode == Input.Keys.DPAD_UP)
particleCount += 5;
else if (keycode == Input.Keys.DPAD_DOWN)
particleCount -= 5;
else if (keycode == Input.Keys.SPACE) {
emitterIndex = (emitterIndex + 1) % emitters.size;
emitter = emitters.get(emitterIndex);
// if we've previously stopped the emitter reset it
if (emitter.isComplete())
emitter.reset();
particleCount = (int) (emitter.getEmission().getHighMax() * emitter.getLife().getHighMax() / 1000f);
} else if (keycode == Input.Keys.ENTER) {
emitter = emitters.get(emitterIndex);
if (emitter.isComplete())
emitter.reset();
else
emitter.allowCompletion();
} else
return false;
particleCount = Math.max(0, particleCount);
if (particleCount > emitter.getMaxParticleCount())
emitter.setMaxParticleCount(particleCount * 2);
emitter.getEmission().setHigh(particleCount / emitter.getLife().getHighMax() * 1000);
effect.getEmitters().clear();
effect.getEmitters().add(emitter);
return false;
}
@Override
public boolean mouseMoved(int x, int y) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
};
Gdx.input.setInputProcessor(inputProcessor);
}
use of com.badlogic.gdx.graphics.g2d.ParticleEmitter in project libgdx by libgdx.
the class EffectPanel method duplicateEmitter.
void duplicateEmitter() {
int row = emitterTable.getSelectedRow();
if (row == -1)
return;
String name = (String) emitterTableModel.getValueAt(row, 0);
addEmitter(name, true, new ParticleEmitter(editor.effect.getEmitters().get(row)));
}
use of com.badlogic.gdx.graphics.g2d.ParticleEmitter in project libgdx by libgdx.
the class EffectPanel method newEmitter.
public ParticleEmitter newEmitter(String name, boolean select) {
final ParticleEmitter emitter = new ParticleEmitter();
emitter.getDuration().setLow(1000);
emitter.getEmission().setHigh(50);
emitter.getLife().setHigh(500);
emitter.getScale().setHigh(32, 32);
emitter.getTint().setColors(new float[] { 1, 0.12156863f, 0.047058824f });
emitter.getTransparency().setHigh(1);
emitter.setMaxParticleCount(25);
emitter.setImagePath(ParticleEditor.DEFAULT_PARTICLE);
addEmitter(name, select, emitter);
return emitter;
}
use of com.badlogic.gdx.graphics.g2d.ParticleEmitter in project libgdx by libgdx.
the class EffectPanel method newExampleEmitter.
public ParticleEmitter newExampleEmitter(String name, boolean select) {
final ParticleEmitter emitter = new ParticleEmitter();
emitter.getDuration().setLow(3000);
emitter.getEmission().setHigh(250);
emitter.getLife().setHigh(500, 1000);
emitter.getLife().setTimeline(new float[] { 0, 0.66f, 1 });
emitter.getLife().setScaling(new float[] { 1, 1, 0.3f });
emitter.getScale().setHigh(32, 32);
emitter.getRotation().setLow(1, 360);
emitter.getRotation().setHigh(180, 180);
emitter.getRotation().setTimeline(new float[] { 0, 1 });
emitter.getRotation().setScaling(new float[] { 0, 1 });
emitter.getRotation().setRelative(true);
emitter.getAngle().setHigh(45, 135);
emitter.getAngle().setLow(90);
emitter.getAngle().setTimeline(new float[] { 0, 0.5f, 1 });
emitter.getAngle().setScaling(new float[] { 1, 0, 0 });
emitter.getAngle().setActive(true);
emitter.getVelocity().setHigh(30, 300);
emitter.getVelocity().setActive(true);
emitter.getTint().setColors(new float[] { 1, 0.12156863f, 0.047058824f });
emitter.getTransparency().setHigh(1, 1);
emitter.getTransparency().setTimeline(new float[] { 0, 0.2f, 0.8f, 1 });
emitter.getTransparency().setScaling(new float[] { 0, 1, 0.75f, 0 });
emitter.setMaxParticleCount(200);
emitter.setImagePath(ParticleEditor.DEFAULT_PARTICLE);
addEmitter(name, select, emitter);
return emitter;
}
use of com.badlogic.gdx.graphics.g2d.ParticleEmitter in project libgdx by libgdx.
the class EffectPanel method addEmitter.
private void addEmitter(String name, boolean select, final ParticleEmitter emitter) {
Array<ParticleEmitter> emitters = editor.effect.getEmitters();
if (emitters.size == 0)
emitter.setPosition(editor.worldCamera.viewportWidth / 2, editor.worldCamera.viewportHeight / 2);
else {
ParticleEmitter p = emitters.get(0);
emitter.setPosition(p.getX(), p.getY());
}
emitters.add(emitter);
emitterTableModel.addRow(new Object[] { name, true });
if (select) {
editor.reloadRows();
int row = emitterTableModel.getRowCount() - 1;
emitterTable.getSelectionModel().setSelectionInterval(row, row);
}
}
Aggregations