只能算是简单的研究了一下,使用了例子里面的图片,当点击屏幕时粒子效果消失。
public class MainActivity extends SimpleBaseGameActivity { private static final int CAMERA_WIDTH = 480; private static final int CAMERA_HEIGHT = 720; private BitmapTextureAtlas mBitmapTextureAtlas; private ITextureRegion mParticleTextureRegion; public EngineOptions onCreateEngineOptions() { final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera); } @Override protected void onCreateResources() { BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); mBitmapTextureAtlas = new BitmapTextureAtlas(getTextureManager(), 32, 32, TextureOptions.BILINEAR); mParticleTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBitmapTextureAtlas, this, "particle_point.png", 0, 0); mBitmapTextureAtlas.load(); } @Override protected Scene onCreateScene() { final Scene scene = new Scene(); scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f)); CircleParticleEmitter emitter = new CircleParticleEmitter(CAMERA_WIDTH / 2, CAMERA_WIDTH / 2, 30);// 圆形粒子生成器,位置在屏幕中央,半径30 final SpriteParticleSystem particleSystem = new SpriteParticleSystem(emitter, 10, 60, 30, mParticleTextureRegion, getVertexBufferObjectManager());// 使用图片作为粒子 particleSystem.addParticleInitializer(new ColorParticleInitializer<Sprite>(1, 0, 0));// 初始化为红色 particleSystem.addParticleInitializer(new AlphaParticleInitializer<Sprite>(0));// 初始化为全透明 particleSystem.addParticleInitializer(new BlendFunctionParticleInitializer<Sprite>(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE)); particleSystem.addParticleInitializer(new VelocityParticleInitializer<Sprite>(-5, 5, 20, 10));// 前两个值为横向加速度的取值范围,后面两个值为纵向加速度取值范围 particleSystem.addParticleInitializer(new RotationParticleInitializer<Sprite>(0.0f, 360.0f));// 旋转角度取值范围 particleSystem.addParticleInitializer(new ExpireParticleInitializer<Sprite>(6));// 单个粒子持续时间 particleSystem.addParticleModifier(new ScaleParticleModifier<Sprite>(0, 5, 1.0f, 2.0f));// 粒子产生过程0-5秒从原始大小变为2倍大小 particleSystem.addParticleModifier(new ColorParticleModifier<Sprite>(0, 3, 1, 1, 0, 0.5f, 0, 0));// 0-3秒间的颜色变化 particleSystem.addParticleModifier(new ColorParticleModifier<Sprite>(4, 6, 1, 1, 0.5f, 1, 0, 1));// 4-6秒间的颜色变化 particleSystem.addParticleModifier(new AlphaParticleModifier<Sprite>(0, 1, 0, 1));// 0-1秒间透明度变化 particleSystem.addParticleModifier(new AlphaParticleModifier<Sprite>(5, 6, 1, 0));// 5-6秒间透明度变化 scene.attachChild(particleSystem); // 屏幕触摸事件 scene.setOnSceneTouchListener(new IOnSceneTouchListener() { public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) { if (pSceneTouchEvent.isActionUp()) { particleSystem.setParticlesSpawnEnabled(false); } return false; } }); return scene; } }如有不对之处,欢迎大家拍砖