@Override public void updateSizes() { waitingToUpdateSize = true; size = 2 * radius; lightSize = 10 * radius; // increase the distance of the lights based on entity's size for (Light aLight : lights) { aLight.setDistance(lightSize); } if (dying) { if (originalRadius / 4 > radius) { for (Light aLight : lights) aLight.setDistance(lightSize * 0.8f); } else { for (Light aLight : lights) aLight.setDistance(lightSize * 3f); } } // Increase texture size sprite.setSize(size, size); // Increase particle size // Fireball giantEffect.getEmitters().get(0).getScale().setLow(3 * radius); giantEffect.getEmitters().get(0).getScale().setHigh(3 * radius); // Core giantEffect.getEmitters().get(1).getScale().setLow(radius); giantEffect.getEmitters().get(1).getScale().setHigh(radius); }
public void draw(SpriteBatch batch) { batch.end(); stage.getBatch().setProjectionMatrix(stage.getCamera().combined); if (eff != null) { if (lastHeroPositionX == 0) lastHeroPositionX = (int) RPG.ctrl.hero.getHeadHero().position.x; else { if (lastHeroPositionX != RPG.ctrl.hero.getHeadHero().position.x) { if (lastHeroPositionX > RPG.ctrl.hero.getHeadHero().position.x) { // LEFT eff.getEmitters().get(0).getVelocity().setHigh(500, 500); } else { eff.getEmitters().get(0).getVelocity().setHigh(-500, -500); } } else { eff.getEmitters().get(0).getVelocity().setHigh(0, 0); } lastHeroPositionX = (int) RPG.ctrl.hero.getHeadHero().position.x; } eff.setPosition(0, GameUtil.getScreenHeight()); stage.getBatch().begin(); eff.draw(stage.getBatch(), Gdx.graphics.getDeltaTime()); stage.getBatch().end(); if (eff.isComplete()) eff.reset(); } batch.begin(); }
void openEffect() { 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 { effect.loadEmitters(Gdx.files.absolute(new File(dir, file).getAbsolutePath())); editor.effect = effect; 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 : 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(); }
@Override public void update(float delta) { if (!active) return; timer += delta; float a = timer / duration; if (a <= 1) { position.x = Interpolation.linear.apply(start.x, target.x, a); position.y = Interpolation.linear.apply(start.y, target.y, a) + ((1 + MathUtils.sinDeg(a * 180)) * 2); light.setDistance(1.5f + MathUtils.random(-.25f, .25f)); } else { effect.allowCompletion(); for (ParticleEmitter emitter : effect.getEmitters()) { emitter.setContinuous(false); } light.setDistance(light.getDistance() * 0.95f); } light.setPosition(position); effect.setPosition(position.x, position.y); effect.update(delta); if (effect.isComplete()) { Gdx.app.log("", "reset"); FlamingRock.pool.free(this); } }
public void init(float x, float y, float tx, float ty) { position.set(x, y); start.set(position); target.set(tx, ty); effect.reset(); duration = target.dst(position) / 6; active = true; light.setActive(true); light.setPosition(x, y); for (ParticleEmitter emitter : effect.getEmitters()) { emitter.setContinuous(true); } }
public ParticleEmitter getEmitter() { return effect.getEmitters().get(effectPanel.editIndex); }
@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 InputProcessorLW() { 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); 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); particleCount = (int) (emitter.getEmission().getHighMax() * emitter.getLife().getHighMax() / 1000f); } 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 touchMoved(int x, int y) { return false; } @Override public boolean scrolled(int amount) { return false; } @Override public void touchTap(int x, int y) { 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); particleCount = (int) (emitter.getEmission().getHighMax() * emitter.getLife().getHighMax() / 1000f); // } 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); effect.setPosition(x, Gdx.graphics.getHeight() - y); } @Override public void touchDrop(int x, int y) { // TODO Auto-generated method stub } }; Gdx.input.setInputProcessor(inputProcessor); }