我正在开发一个游戏项目,想知道在SpriteParticleSystem
设置点击事件,因为我已将粒子数设置为一个。
如何使这个粒子可点击?
{
// B1= new ButtonSprite(8, 12, this.mParticleTextureRegion, this.getVertexBufferObjectManager());
final SpriteParticleSystem particleSystem1 = new SpriteParticleSystem(new PointParticleEmitter(GameActivity.CAMERA_WIDTH - 200, GameActivity.CAMERA_HEIGHT), 8, 12, 1, this.player, this.getVertexBufferObjectManager());
particleSystem1.addParticleInitializer(new VelocityParticleInitializer<Sprite>(-15, -22, -70, -90));
particleSystem1.addParticleInitializer(new AccelerationParticleInitializer<Sprite>(0, 15));
particleSystem1.addParticleInitializer(new RotationParticleInitializer<Sprite>(0.0f, 360.0f));
particleSystem1.addParticleInitializer(new ExpireParticleInitializer<Sprite>(11.5f));
particleSystem1.addParticleModifier(new AlphaParticleModifier<Sprite>(2.5f, 3.5f, 1.0f, 0.0f));
particleSystem1.addParticleModifier(new AlphaParticleModifier<Sprite>(3.5f, 4.5f, 0.0f, 1.0f));
particleSystem1.addParticleModifier(new AlphaParticleModifier<Sprite>(4.5f, 11.5f, 1.0f, 0.0f));
scene.attachChild(particleSystem1);
}
/* Left to right Particle System. */
{
particleSystem2 = new SpriteParticleSystem(new PointParticleEmitter(200, GameActivity.CAMERA_HEIGHT), 6, 30000, 1, this.mParticleTextureRegion, this.getVertexBufferObjectManager());
//particleSystem2.addParticleInitializer(new BlendFunctionParticleInitializer<Sprite>(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE));
particleSystem2.addParticleInitializer(new VelocityParticleInitializer<Sprite>(15, 22, -60, -90));
particleSystem2.addParticleInitializer(new AccelerationParticleInitializer<Sprite>(-1, 15));
particleSystem2.addParticleInitializer(new RotationParticleInitializer<Sprite>(0.0f, 360.0f));
//particleSystem2.addParticleInitializer(new ColorParticleInitializer<Sprite>(1.0f, 0.0f, 0.0f));
particleSystem2.addParticleInitializer(new ExpireParticleInitializer<Sprite>(11.5f));
//particleSystem.addParticleModifier(new ScaleParticleModifier<Sprite>(0, 5, 0.5f, 2.0f));
particleSystem2.addParticleModifier(new AlphaParticleModifier<Sprite>(2.5f, 3.5f, 1.0f, 0.0f));
particleSystem2.addParticleModifier(new AlphaParticleModifier<Sprite>(3.5f, 4.5f, 0.0f, 1.0f));
//particleSystem.addParticleModifier(new ColorParticleModifier<Sprite>(0.0f, 11.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f));
particleSystem2.addParticleModifier(new AlphaParticleModifier<Sprite>(4.5f, 11.5f, 1.0f, 0.0f));
scene.attachChild(particleSystem2);
}
答案 0 :(得分:2)
我不是百分百确定它是否有用,但试试这个:
final IParticleInitializer iPartInit = new IParticleInitializer() {
@Override
public void onInitializeParticle(Particle pParticle) {
Particle temp = new Particle(pParticle.getX(), pParticle.getY(), pParticle.getTextureRegion()) //make a temporary particle that you can override the onTouchArea of
{
@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
float pTouchAreaLocalX, float pTouchAreaLocalY) {
int eventaction = pSceneTouchEvent.getAction();
switch (eventaction) {
case TouchEvent.ACTION_DOWN:
//do whatever you want
break;
}
return true;
}
};
pParticle = temp;
}
particleSystem1.addParticleInitializer(iPartInit);
初始化粒子系统后立即使用。