List of usage examples for com.badlogic.gdx.graphics.g2d ParticleEmitter getImagePath
public String getImagePath()
From source file:com.lynk.gdx.tool.particleeditor.EffectPanel.java
License:Apache License
void saveEffect() { FileDialog dialog = new FileDialog(editor, "Save Effect", FileDialog.SAVE); if (lastDir != null) dialog.setDirectory(lastDir);/*from w w w.j ava2 s .c o m*/ dialog.setVisible(true); String file = dialog.getFile(); String dir = dialog.getDirectory(); if (dir == null || file == null || file.trim().length() == 0) return; lastDir = dir; int index = 0; File effectFile = new File(dir, file); // save each image path as relative path to effect file directory URI effectDirUri = effectFile.getParentFile().toURI(); for (ParticleEmitter emitter : editor.effect.getEmitters()) { emitter.setName((String) emitterTableModel.getValueAt(index++, 0)); String imagePath = emitter.getImagePath(); if ((imagePath.contains("/") || imagePath.contains("\\")) && !imagePath.contains("..")) { // it's absolute, make it relative: URI imageUri = new File(emitter.getImagePath()).toURI(); emitter.setImagePath(effectDirUri.relativize(imageUri).getPath()); } } File outputFile = new File(dir, file); Writer fileWriter = null; try { fileWriter = new FileWriter(outputFile); editor.effect.save(fileWriter); } catch (Exception ex) { System.out.println("Error saving effect: " + outputFile.getAbsolutePath()); ex.printStackTrace(); JOptionPane.showMessageDialog(editor, "Error saving effect."); } finally { StreamUtils.closeQuietly(fileWriter); } }
From source file:com.lynk.gdx.tool.particleeditor.ParticleEditor.java
License:Apache License
public ImageIcon getIcon(ParticleEmitter emitter) { ParticleData data = particleData.get(emitter); if (data == null) particleData.put(emitter, data = new ParticleData()); String imagePath = emitter.getImagePath(); if (data.icon == null && imagePath != null) { try {/*from www . ja v a 2s. c o m*/ URL url; File file = new File(imagePath); if (file.exists()) url = file.toURI().toURL(); else { url = ParticleEditor.class.getResource(imagePath); if (url == null) return null; } data.icon = new ImageIcon(url); } catch (MalformedURLException ex) { ex.printStackTrace(); } } return data.icon; }
From source file:com.westernarc.easterrun.gdx.graphics.g2d.ParticleEffect.java
License:Apache License
public void save(File file) { Writer output = null;/*from www . j a v a2s . co m*/ try { output = new FileWriter(file); int index = 0; for (int i = 0, n = emitters.size; i < n; i++) { ParticleEmitter emitter = emitters.get(i); if (index++ > 0) output.write("\n\n"); emitter.save(output); output.write("- Image Path -\n"); output.write(emitter.getImagePath() + "\n"); } } catch (IOException ex) { throw new GdxRuntimeException("Error saving effect: " + file, ex); } finally { try { if (output != null) output.close(); } catch (IOException ex) { } } }
From source file:com.westernarc.easterrun.gdx.graphics.g2d.ParticleEffect.java
License:Apache License
public void loadEmitterImages(TextureAtlas atlas) { for (int i = 0, n = emitters.size; i < n; i++) { ParticleEmitter emitter = emitters.get(i); String imagePath = emitter.getImagePath(); if (imagePath == null) continue; String imageName = new File(imagePath.replace('\\', '/')).getName(); int lastDotIndex = imageName.lastIndexOf('.'); if (lastDotIndex != -1) imageName = imageName.substring(0, lastDotIndex); Sprite sprite = atlas.createSprite(imageName); if (sprite == null) throw new IllegalArgumentException("SpriteSheet missing image: " + imageName); emitter.setSprite(sprite);/*w w w .j av a 2 s . co m*/ } }
From source file:com.westernarc.easterrun.gdx.graphics.g2d.ParticleEffect.java
License:Apache License
public void loadEmitterImages(FileHandle imagesDir) { for (int i = 0, n = emitters.size; i < n; i++) { ParticleEmitter emitter = emitters.get(i); String imagePath = emitter.getImagePath(); if (imagePath == null) continue; String imageName = new File(imagePath.replace('\\', '/')).getName(); emitter.setSprite(new Sprite(loadTexture(imagesDir.child(imageName)))); }/*from ww w .j ava2 s .co m*/ }