在我的游戏中,我使用
static final float FRUSTUM_WIDTH = 10;
static final float FRUSTUM_HEIGHT = 15;
所以当我绘制粒子时,它们占据了整个屏幕并且非常大!那么如何缩小它们以满足我的需求呢?
//皮尤实验室
ParticleEffect pe = new ParticleEffect();
pe.load(Gdx.files.internal("data/particle/particle.p"), Gdx.files.internal("data/particle"));
pe.setPosition(x, y);
float pScale = 0.2f;
float scaling = pe.getEmitters().get(0).getScale().getHighMax();
pe.getEmitters().get(0).getScale().setHigh(scaling * pScale);
scaling = pe.getEmitters().get(0).getScale().getLowMax();
pe.getEmitters().get(0).getScale().setLow(scaling * pScale);
scaling = pe.getEmitters().get(0).getVelocity().getHighMax();
pe.getEmitters().get(0).getVelocity().setHigh(scaling * pScale);
scaling = pe.getEmitters().get(0).getVelocity().getLowMax();
pe.getEmitters().get(0).getVelocity().setLow(scaling * pScale);
要么使用粒子编辑器(老实说,我认为调整粒子大小不是一个好主意,因为你提到粒子不会变得太小(对于其他任何我真的推荐它))或者你只是打开粒子效果文件。它应该由编辑器生成,或者您可以从示例中复制它。在此文件中搜索以下字段:
- Scale -
lowMin: 0.0
lowMax: 0.0
highMin: 0.6
highMax: 0.6
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
根据需要调整highMin
和highMax
。
好吧,您可以使用粒子编辑器并在那里调整大小:
我使用了与 Victor 相同的方法,但对我有用的是:
ParticleEffect effect = new ParticleEffect();
effect.load(Gdx.files.internal("particle/version1.p"), Gdx.files.internal("particle"));
effect.setPosition(x, .y);
float pScale = 0.02f;
float scaling;
Array<ParticleEmitter> emitters = effect.getEmitters();
for (ParticleEmitter e : emitters) {
scaling = e.getScale().getHighMax();
e.getScale().setHigh(scaling * pScale);
scaling = e.getScale().getLowMax();
e.getScale().setLow(scaling * pScale);
scaling = e.getVelocity().getHighMax();
e.getVelocity().setHigh(scaling * pScale);
scaling = e.getVelocity().getLowMax();
e.getVelocity().setLow(scaling * pScale);
scaling = e.getSpawnHeight().getHighMax();
e.getSpawnHeight().setHighMax(scaling * pScale);
scaling = e.getSpawnHeight().getLowMax();
e.getSpawnHeight().setLowMax(scaling * pScale);
scaling = e.getSpawnHeight().getHighMin();
e.getSpawnHeight().setHighMin(scaling * pScale);
scaling = e.getSpawnHeight().getLowMin();
e.getSpawnHeight().setLowMin(scaling * pScale);
scaling = e.getSpawnWidth().getHighMax();
e.getSpawnWidth().setHighMax(scaling * pScale);
scaling = e.getSpawnWidth().getLowMax();
e.getSpawnWidth().setLowMax(scaling * pScale);
scaling = e.getSpawnWidth().getHighMin();
e.getSpawnWidth().setHighMin(scaling * pScale);
scaling = e.getSpawnWidth().getLowMin();
e.getSpawnWidth().setLowMin(scaling * pScale);
scaling = e.getXOffsetValue().getLowMax();
e.getXOffsetValue().setLowMax(scaling * pScale);
scaling = e.getXOffsetValue().getLowMin();
e.getXOffsetValue().setLowMin(scaling * pScale);
scaling = e.getYOffsetValue().getLowMax();
e.getYOffsetValue().setLowMax(scaling * pScale);
scaling = e.getYOffsetValue().getLowMin();
e.getYOffsetValue().setLowMin(scaling * pScale);
}
effect.start();
就个人而言,为了根据用户的屏幕处理我的粒子大小,我使用ScalingViewport
它允许您以固定大小工作,并且它会根据设备的屏幕大小自动缩放。我通常将ScalingViewport
for aScaling.fill
放在它的构造函数中;这可以防止粒子拉伸并看起来很糟糕。