本文整理汇总了Java中com.badlogic.gdx.graphics.g2d.ParticleEmitter类的典型用法代码示例。如果您正苦于以下问题:Java ParticleEmitter类的具体用法?Java ParticleEmitter怎么用?Java ParticleEmitter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParticleEmitter类属于com.badlogic.gdx.graphics.g2d包,在下文中一共展示了ParticleEmitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: widen
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
/**
* Widens the emission angle of the supplied emitters
* by the supplied coefficient.
*
* @param pe
* @param coef
*/
public static void widen(Array<ParticleEmitter> emitters, float coef) {
for (ParticleEmitter e : emitters) {
float highMin = e.getAngle().getHighMin();
float highMax = e.getAngle().getHighMax();
float oldDist = (highMax - highMin);
float newDist = oldDist * coef;
float distDif = newDist - oldDist;
e.getAngle().setHighMax(highMax + distDif / 2);
e.getAngle().setHighMin(highMin - distDif / 2);
float lowMin = e.getAngle().getLowMin();
float lowMax = e.getAngle().getLowMax();
oldDist = (lowMax - lowMin);
newDist = oldDist * coef;
distDif = newDist - oldDist;
e.getAngle().setLowMax(lowMax + distDif / 2);
e.getAngle().setLowMin(lowMin - distDif / 2);
}
}
示例2: update
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
@Override
public void update(float deltaTime) {
if (attachedObj != null) {
setPosition(attachedObj.getX() + objOffsetX, attachedObj.getY() + objOffsetY);
}
if (loopPosition > 0) {
for (ParticleEmitter emitter : getEmitters()) {
if (emitter.durationTimer > loopPosition) {
emitter.durationTimer = loopPosition;
}
}
}
super.update(deltaTime);
}
示例3: addEffect
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
public void addEffect(String name, Vector2 position, float angle){
logger.debug("Creating effect: " + name);
ParticleEffect effect = App.assets.getEffect(name);
if (effect == null) {
logger.error("Couldn't create particle effect: " + name);
return;
}
ParticleEffect e = new ParticleEffect(effect);
for (ParticleEmitter emitter : e.getEmitters()){
float a1 = emitter.getAngle().getHighMin(),
a2 = emitter.getAngle().getHighMax();
emitter.getRotation().setHighMin(a1 + angle);
emitter.getRotation().setHighMax(a2 + angle);
}
e.setPosition(position.x * App.engine.PIXELS_PER_METER, position.y * App.engine.PIXELS_PER_METER);
e.start();
effects.add(e);
}
示例4: getIcon
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
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 {
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;
}
示例5: loadImage
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
private void loadImage (ParticleEmitter emitter) {
final String imagePath = emitter.getImagePath();
String imageName = new File(imagePath.replace('\\', '/')).getName();
try {
FileHandle file;
if (imagePath.equals(ParticleEditor.DEFAULT_PARTICLE) || imagePath.equals(ParticleEditor.DEFAULT_PREMULT_PARTICLE))
file = Gdx.files.classpath(imagePath);
else
file = Gdx.files.absolute(imagePath);
emitter.setSprite(new Sprite(new Texture(file)));
} catch (GdxRuntimeException ex) {
ex.printStackTrace();
EventQueue.invokeLater(new Runnable() {
public void run () {
JOptionPane.showMessageDialog(ParticleEditor.this, "Error loading image:\n" + imagePath);
}
});
emitter.setImagePath(null);
}
}
示例6: newEmitter
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
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;
}
示例7: addEmitter
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
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);
}
}
示例8: saveEffect
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
void saveEffect () {
FileDialog dialog = new FileDialog(editor, "Save Effect", FileDialog.SAVE);
if (lastDir != null) dialog.setDirectory(lastDir);
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;
for (ParticleEmitter emitter : editor.effect.getEmitters())
emitter.setName((String)emitterTableModel.getValueAt(index++, 0));
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);
}
}
示例9: resetEffect
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
public void resetEffect() {
stopped = false;
playbackTime = 0f;
playbackDuration = 1f + Random.randomInt(1.75f, 4.5f);
activeEffect.setPosition(Random.randomInt(worldBounds.x, worldBounds.width + 1), Random.randomInt(worldBounds.y, worldBounds.height + 1));
for (ParticleEmitter emitter : activeEffect.getEmitters()) {
emitter.reset();
if (!emitter.getName().contains("smoke")) {
emitter.getTint().setColors(colorsIterator.next());
}
}
}
示例10: getIcon
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
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 {
URL url;
File file = new File(imagePath);
if (file.exists())
url = file.toURI().toURL();
else {
url = ParticlePanel.class.getResource(imagePath);
if (url == null) return null;
}
data.icon = new ImageIcon(url);
} catch (MalformedURLException ex) {
ex.printStackTrace();
}
}
return data.icon;
}
示例11: newEmitter
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
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.setFlip(false, true);
emitter.setMaxParticleCount(25);
emitter.setImagePath("particle.png");
addEmitter(name, select, emitter);
return emitter;
}
示例12: saveEffect
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
void saveEffect () {
FileDialog dialog = new FileDialog((Frame) null, "Save Effect", FileDialog.SAVE);
if (lastDir != null) dialog.setDirectory(lastDir);
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;
for (ParticleEmitter emitter : editor.effect.getEmitters())
emitter.setName((String)emitterTableModel.getValueAt(index++, 0));
try {
editor.effect.save(new File(dir, file));
} catch (Exception ex) {
System.out.println("Error saving effect: " + new File(dir, file).getAbsolutePath());
ex.printStackTrace();
JOptionPane.showMessageDialog(editor, "Error saving effect.");
}
}
示例13: loadImage
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
private void loadImage (ParticleEmitter emitter) {
final String imagePath = emitter.getImagePath();
String imageName = new File(imagePath.replace('\\', '/')).getName();
try {
FileHandle file;
if (imagePath.equals("particle.png"))
file = Gdx.files.classpath(imagePath);
else
file = Gdx.files.absolute(imagePath);
emitter.setSprite(new Sprite(new Texture(file)));
} catch (GdxRuntimeException ex) {
ex.printStackTrace();
EventQueue.invokeLater(new Runnable() {
public void run () {
JOptionPane.showMessageDialog(ParticleRenderer.this.particlePanel, "Error loading image:\n" + imagePath);
}
});
emitter.setImagePath(null);
}
}
示例14: addParticle
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
/**
* Adds a ParticleEffect from a ParticleEffectVO. Uses ParticleEmitterBox2D
* @param item ParticleEffectVO to add
*/
private static void addParticle(ParticleEffectVO item) {
ParticleEffect particleEffect = new ParticleEffect();
particleEffect.load(Gdx.files.internal(particlesPath + "/" + item.particleName), atlas);
particleEffect.scaleEffect(ZeroBit.pixelsToMeters * item.scaleX);
for (int i=0; i < particleEffect.getEmitters().size; i++) {
particleEffect.getEmitters().set(i, new ParticleEmitterBox2D(b2dSystem.getB2World(), particleEffect.getEmitters().get(i)));
ParticleEmitter emitter = particleEffect.getEmitters().get(i);
// Spawn scaling doesn't seem to alter the actual dimensions of the effect like in the editor
/*emitter.getSpawnWidth().setHigh(emitter.getSpawnWidth().getHighMin() * item.scaleX, emitter.getSpawnWidth().getHighMax() * item.scaleX);
emitter.getSpawnWidth().setLow(emitter.getSpawnWidth().getLowMin() * item.scaleX, emitter.getSpawnWidth().getLowMax() * item.scaleX);
emitter.getSpawnHeight().setHigh(emitter.getSpawnHeight().getHighMin() * item.scaleY, emitter.getSpawnHeight().getHighMax() * item.scaleY);
emitter.getSpawnHeight().setLow(emitter.getSpawnHeight().getLowMin() * item.scaleY, emitter.getSpawnHeight().getLowMax() * item.scaleY);*/
emitter.setPosition(item.x * ZeroBit.pixelsToMeters, item.y * ZeroBit.pixelsToMeters);
}
//entityManager.getEngine().getSystem(RenderingSystem.class).addParticle(particleEffect);
ParticleComponent pc = new ParticleComponent();
pc.addParticle(particleEffect);
addEntity(item, null, pc, new VisualComponent());
}
示例15: setAlpha
import com.badlogic.gdx.graphics.g2d.ParticleEmitter; //导入依赖的package包/类
@Override
public void setAlpha(float alpha) {
// TODO: Alpha doesn't work for particles here as intended :(
this.alpha = alpha;
for (ParticleEffect e : effects.keySet()) {
for (ParticleEmitter emitter : e.getEmitters()) {
ScaledNumericValue v = emitter.getTransparency();
v.setHigh(alpha);
v.setLow(alpha);
}
}
}