Back to project page ssniper-andengine.
The source code is released under:
Apache License
If you think the Android project ssniper-andengine listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.cladophora.ssniper; // w ww . j av a 2s. c om import org.andengine.engine.handler.timer.ITimerCallback; import org.andengine.engine.handler.timer.TimerHandler; import org.andengine.entity.IEntity; import org.andengine.entity.IEntityFactory; import org.andengine.entity.particle.ParticleSystem; import org.andengine.entity.particle.emitter.PointParticleEmitter; import org.andengine.entity.particle.initializer.VelocityParticleInitializer; import org.andengine.entity.particle.modifier.AlphaParticleModifier; import org.andengine.entity.particle.modifier.RotationParticleModifier; import org.andengine.entity.primitive.Rectangle; import org.andengine.ui.activity.SimpleBaseGameActivity; import org.andengine.util.color.Color; /** * Created by jmar on 1/26/14. */ public class GameEffects { public static void createExplosion(final float posX, final float posY, final IEntity target, final SimpleBaseGameActivity activity) { final int nParticles = 128; final float effectDuration = GameEvents.ENEMY_DEATH_ANIMATION_DURATION / 0.6f; final float particleSizeX = 2 / target.getScaleX(); final float particleSizeY = 2 / target.getScaleY(); PointParticleEmitter particleEmitter = new PointParticleEmitter(posX, posY); IEntityFactory<Rectangle> recFact = new IEntityFactory<Rectangle>() { @Override public Rectangle create(final float pX, final float pY) { Rectangle rect = new Rectangle(posX, posY, particleSizeX, particleSizeY, activity.getVertexBufferObjectManager()); rect.setColor(Color.RED); return rect; } }; final ParticleSystem<Rectangle> particleSystem = new ParticleSystem<Rectangle>(recFact, particleEmitter, 800, 1500, nParticles); particleSystem.addParticleInitializer(new VelocityParticleInitializer<Rectangle>(-150, 0, -60, 30)); particleSystem.addParticleModifier(new AlphaParticleModifier<Rectangle>(0, 0.6f * effectDuration, 1, 0)); particleSystem.addParticleModifier(new RotationParticleModifier<Rectangle>(0, effectDuration, 0, 360)); particleSystem.setX(posX); particleSystem.setY(posY); target.attachChild(particleSystem); target.registerUpdateHandler( new TimerHandler(effectDuration, new ITimerCallback() { @Override public void onTimePassed(final TimerHandler pTimerHandler) { particleSystem.detachSelf(); //target.sortChildren(); target.unregisterUpdateHandler(pTimerHandler); } } ) ); } public static void createSmallExplosion(final float posX, final float posY, final IEntity target, final SimpleBaseGameActivity activity) { final int nParticles = 64; final float effectDuration = GameEvents.ENEMY_DEATH_ANIMATION_DURATION * 2; final float particleSizeX = 2 / target.getScaleX(); final float particleSizeY = 2 / target.getScaleY(); PointParticleEmitter particleEmitter = new PointParticleEmitter(posX, posY); IEntityFactory<Rectangle> recFact = new IEntityFactory<Rectangle>() { @Override public Rectangle create(final float pX, final float pY) { Rectangle rect = new Rectangle(posX, posY, particleSizeX, particleSizeY, activity.getVertexBufferObjectManager()); rect.setColor(Color.RED); return rect; } }; final ParticleSystem<Rectangle> particleSystem = new ParticleSystem<Rectangle>(recFact, particleEmitter, 350, 500, nParticles); particleSystem.addParticleInitializer(new VelocityParticleInitializer<Rectangle>(-40, 40, -80, 20)); particleSystem.addParticleModifier(new AlphaParticleModifier<Rectangle>(0, 0.6f * effectDuration, 1, 0)); particleSystem.addParticleModifier(new RotationParticleModifier<Rectangle>(0, effectDuration, 0, 360)); particleSystem.setX(posX); particleSystem.setY(posY); target.attachChild(particleSystem); target.registerUpdateHandler( new TimerHandler(effectDuration, new ITimerCallback() { @Override public void onTimePassed(final TimerHandler pTimerHandler) { particleSystem.detachSelf(); //target.sortChildren(); target.unregisterUpdateHandler(pTimerHandler); } } ) ); } }