Search in sources :

Example 6 with ParticleEmitter

use of com.badlogic.gdx.graphics.g2d.ParticleEmitter in project libgdx by libgdx.

the class EffectPanel method openEffect.

void openEffect(boolean mergeIntoCurrent) {
    FileDialog dialog = new FileDialog(editor, "Open Effect", FileDialog.LOAD);
    if (lastDir != null)
        dialog.setDirectory(lastDir);
    dialog.setVisible(true);
    final String file = dialog.getFile();
    final String dir = dialog.getDirectory();
    if (dir == null || file == null || file.trim().length() == 0)
        return;
    lastDir = dir;
    ParticleEffect effect = new ParticleEffect();
    try {
        File effectFile = new File(dir, file);
        effect.loadEmitters(Gdx.files.absolute(effectFile.getAbsolutePath()));
        if (mergeIntoCurrent) {
            for (ParticleEmitter emitter : effect.getEmitters()) {
                addEmitter(emitter.getName(), false, emitter);
            }
        } else {
            editor.effect = effect;
            editor.effectFile = effectFile;
        }
        emitterTableModel.getDataVector().removeAllElements();
        editor.particleData.clear();
    } catch (Exception ex) {
        System.out.println("Error loading effect: " + new File(dir, file).getAbsolutePath());
        ex.printStackTrace();
        JOptionPane.showMessageDialog(editor, "Error opening effect.");
        return;
    }
    for (ParticleEmitter emitter : editor.effect.getEmitters()) {
        emitter.setPosition(editor.worldCamera.viewportWidth / 2, editor.worldCamera.viewportHeight / 2);
        emitterTableModel.addRow(new Object[] { emitter.getName(), true });
    }
    editIndex = 0;
    emitterTable.getSelectionModel().setSelectionInterval(editIndex, editIndex);
    editor.reloadRows();
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect) ParticleEmitter(com.badlogic.gdx.graphics.g2d.ParticleEmitter) File(java.io.File)

Example 7 with ParticleEmitter

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);
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect) Array(com.badlogic.gdx.utils.Array) ParticleEmitter(com.badlogic.gdx.graphics.g2d.ParticleEmitter) InputProcessor(com.badlogic.gdx.InputProcessor) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 8 with ParticleEmitter

use of com.badlogic.gdx.graphics.g2d.ParticleEmitter in project libgdx by libgdx.

the class EffectPanel method move.

void move(int direction) {
    if (direction < 0 && editIndex == 0)
        return;
    Array<ParticleEmitter> emitters = editor.effect.getEmitters();
    if (direction > 0 && editIndex == emitters.size - 1)
        return;
    int insertIndex = editIndex + direction;
    Object name = emitterTableModel.getValueAt(editIndex, 0);
    emitterTableModel.removeRow(editIndex);
    ParticleEmitter emitter = emitters.removeIndex(editIndex);
    emitterTableModel.insertRow(insertIndex, new Object[] { name });
    emitters.insert(insertIndex, emitter);
    editIndex = insertIndex;
    emitterTable.getSelectionModel().setSelectionInterval(editIndex, editIndex);
}
Also used : ParticleEmitter(com.badlogic.gdx.graphics.g2d.ParticleEmitter)

Aggregations

ParticleEmitter (com.badlogic.gdx.graphics.g2d.ParticleEmitter)8 ParticleEffect (com.badlogic.gdx.graphics.g2d.ParticleEffect)2 File (java.io.File)2 InputProcessor (com.badlogic.gdx.InputProcessor)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 Array (com.badlogic.gdx.utils.Array)1 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 URI (java.net.URI)1