我的libgdx项目的所有图像都放在一个纹理中。
我将添加一些不错的粒子效果,但是文档暗示每种类型的发射器都需要为其粒子使用单独的图形文件。
真的吗?或者,是否有一种方法指定纹理的区域以用作粒子图像,这样我仍可以将所有图像保留在该单个文件中?
是的,可以,但是您需要在TextureAtlas
。看看这篇文章吧。
这是一个我什至使用TextureAtlas的示例:
m_effect = new ParticleEffect();
m_effect.load(Gdx.files.internal("particle/effects/lightning.p"), this.getAtlas());
或分两个步骤:
m_effect.loadEmitters(Gdx.files.internal("particle/effects/lightning.p"));
m_effect.loadEmitterImages(this.getAtlas());
这是他的LoadEmitterImage
工作:
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); /// <---- here it creates a Sprite with a textureregion
if (sprite == null) throw new IllegalArgumentException("SpriteSheet missing image: " + imageName);
emitter.setSprite(sprite);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句