1

我正在开发一个游戏项目,并且想知道将点击事件设置为打开,SpriteParticleSystem因为我已将粒子数设置为 1。

如何使这个粒子可点击?

{
    // 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);
}
4

1 回答 1

2

I'm not 100% sure if it'll work, but try this:

    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);

Use this right after initializing the particle system.

于 2013-05-16T16:25:08.573 回答