1: Circular particle transmitter: when you touch it by hand, you can generate a circular particle transmitter to achieve the flame burning effect: The following is a simple demo:
Package org. andengine. examples;
Import Org. andengine. engine. camera. camera; import Org. andengine. engine. options. engineoptions; import Org. andengine. engine. options. screenorientation; import Org. andengine. engine. options. resolutionpolicy. ratioresolutionpolicy; import Org. andengine. entity. particle. spriteparticlesystem; import Org. andengine. entity. particle. emitter. circleoutlineparticleemitter; import Org. andengine. entity. particle. initializer. alphaparticleinitializer; import Org. andengine. entity. particle. initializer. blendfunctionparticipant leinitializer; import Org. andengine. entity. particle. initializer. colorparticle initializer; import Org. andengine. entity. particle. initializer. rotationparticipant leinitializer; import Org. andengine. entity. particle. initializer. velocityparticipant leinitializer; import Org. andengine. entity. particle. modifier. alphaparticlemodifier; import Org. andengine. entity. particle. modifier. colorparticle modifier; import Org. andengine. entity. particle. modifier. expireparticipant leinitializer; import Org. andengine. entity. particle. modifier. scaleparticlemodifier; import Org. andengine. entity. scene. ionscenetouchlistener; import Org. andengine. entity. scene. scene; import Org. andengine. entity. sprite. sprite; import Org. andengine. entity. util. fpslogger; import Org. andengine. input. touch. touchevent; import Org. andengine. openGL. texture. textureoptions; import Org. andengine. openGL. texture. atlas. bitmap. bitmaptextureatlas; import Org. andengine. openGL. texture. atlas. bitmap. bitmaptextureatlastextureregionfactory; import Org. andengine. openGL. texture. region. itextureregion; import Org. andengine. UI. activity. simplebasegameactivity;
Import Android. OpenGL. gles20; import Android. widget. Toast;
/*** (C) 2010 Nicolas gramlich * (c) 2011 Zynga ** @ author Nicolas gramlich * @ since 11:54:51-03.04.2010 */public class participant systemsimpleexample extends simplebasegameactivity {// ======== ========================================================== ====/constants // ========================================== ======================================
Private Static final int camera_width = 720; Private Static final int camera_height = 480;
// ================================================ ====================================/// Fields // ====================== ========================================================== =====
Private camera mcamera; private bitmaptextureatlas mbitmaptextureatlas; private itextureregion mparticletextureregion;
// ================================================ ====================================/// Constructors // ======================== ========================================================== =====
// ================================================ ==================================/// Getter & setter // ================== ========================================================== ========
// ================================================ ====================================/// Methods for/from superclass/interfaces // ========== ========================================================== ==============
@ Override public engineoptions oncreateengineoptions () {toast. maketext (this, "touch the screen to move the participant system.", Toast. length_long). Show ();
This. mcamera = new camera (0, 0, participant systemsimpleexample. camera_width, participant systemsimpleexample. camera_height );
Return new engineoptions (true, screenorientation. landscape_fixed, new ratioresolutionpolicy (participant systemsimpleexample. camera_width, participant systemsimpleexample. camera_height), this. mcamera );}
@ Override protected void oncreateresources () {bitmaptextureatlastextureregionfactory. setassetbasepath ("GFX /");
This. mbitmaptextureatlas = new bitmaptextureatlas (this. gettexturemanager (), 32, 32, textureoptions. bilinear_premultiplyalpha); this. mparticletextureregion = bitmaptextureatlastextureregionfactory. createfromasset (this. mbitmaptextureatlas, this, "maid", 0, 0 );
This. mbitmaptextureatlas. Load ();}
@ Override protected scene oncreatescene () {This. mengine. registerupdatehandler (New fpslogger ());
Final scene = new scene ();
// Define the circular particle transmitter. The parameters are the circular coordinates and radius of the transmitter in sequence.
Final circleoutlineparticleemitter participant leemitter = new circleoutlineparticleemitter (participant systemsimpleexample. camera_width * 0.5f, participant systemsimpleexample. camera_height * 0.5f + 20, 80 );
// Only the particle transmitter is not enough. A particle system needs to be defined. The system references the previously defined particle transmitter and defines the emission speed, angle and other final spriteparticlesystem particle system = new spriteparticlesystem (FIG, 60, 60,360, this. mparticletextureregion, this. getvertexbufferobjectmanager ());
// Add touch events for the scenario
Scene. setonscenetouchlistener (New ionscenetouchlistener () {@ override public Boolean onscenetouchevent (final scene pscene, final touchevent pscenetouchevent) {participant emitter. setcenter (pscenetouchevent. getx (), pscenetouchevent. gety (); Return true ;}});
Only after a series of animations are implemented by the particle system can the flame effect be more realistic, so it is the initialization of various animation effects.
Particle System. addparticipant leinitializer (New colorparticipant leinitializer <sprite> (1, 0, 0); participant system. addparticle initializer (New alphaparticleinitializer <sprite> (0); particle system. addparticipant leinitializer (New blendfunctionparticipant leinitializer <sprite> (gles1_gl _ src_alpha, gles1_gl _ One); participant system. addparticle initializer (New velocityparticle initializer <sprite> (-2, 2,-20,-10); particle system. addparticle initializer (New rotationparticle initializer <sprite> (0.0f, 360.0f); particle system. addparticipant leinitializer (New expireparticipant leinitializer <sprite> (6); // defines the flame burning time.
// After Initializing Various parameters, I also make some parameters dynamically change to realize the flame burning action.
Particle System. addparticle modifier (New scaleparticlemodifier <sprite> (0, 5, 1.0f, 2.0f); particle system. addparticipant lemodifier (New colorparticipant lemodifier <sprite> (0, 3, 1, 1, 0, 0.5f, 0, 0); participant system. addparticle modifier (New colorparticle modifier <sprite> (4, 6, 1, 1, 0.5f, 1, 0, 1); particle system. addparticipant lemodifier (New alphaparticlemodifier <sprite> (0, 1, 0, 1. addparticipant lemodifier (New alphaparticlemodifier <sprite> (5, 6, 1, 0 ));
Scene. attachchild (participant system); // Add the particle system to the scene
Return scene ;}
// ================================================ ======================================/// Methods // ========================================================== =====
// ================================================ ======================================/Inner and anonymous classes // ================ ========================================================== =======}
The following is an example of the non-circular flame effect. The Code is as follows:
========================================================== ====================================
Package org. andengine. examples;
Import Org. andengine. engine. camera. camera; import Org. andengine. engine. options. engineoptions; import Org. andengine. engine. options. screenorientation; import Org. andengine. engine. options. resolutionpolicy. ratioresolutionpolicy; import Org. andengine. entity. particle. spriteparticlesystem; import Org. andengine. entity. particle. emitter. pointparticipant leemitter; import Org. andengine. entity. particle. initializer. accelerationparticipant leinitializer; import Org. andengine. entity. particle. initializer. blendfunctionparticipant leinitializer; import Org. andengine. entity. particle. initializer. colorparticle initializer; import Org. andengine. entity. particle. initializer. rotationparticipant leinitializer; import Org. andengine. entity. particle. initializer. velocityparticipant leinitializer; import Org. andengine. entity. particle. modifier. alphaparticlemodifier; import Org. andengine. entity. particle. modifier. colorparticle modifier; import Org. andengine. entity. particle. modifier. expireparticipant leinitializer; import Org. andengine. entity. particle. modifier. scaleparticlemodifier; import Org. andengine. entity. scene. scene; import Org. andengine. entity. scene. background. background; import Org. andengine. entity. sprite. sprite; import Org. andengine. entity. util. fpslogger; import Org. andengine. openGL. texture. textureoptions; import Org. andengine. openGL. texture. atlas. bitmap. bitmaptextureatlas; import Org. andengine. openGL. texture. atlas. bitmap. bitmaptextureatlastextureregionfactory; import Org. andengine. openGL. texture. region. itextureregion; import Org. andengine. UI. activity. simplebasegameactivity;
Import Android. OpenGL. gles20;
/*** (C) 2010 Nicolas gramlich * (c) 2011 Zynga ** @ author Nicolas gramlich * @ since 16:44:30-292.166.2010 */public class participant systemnexusexample extends simplebasegameactivity {// ======== ========================================================== ====/constants // ========================================== ======================================
Private Static final int camera_width = 480; Private Static final int camera_height = 320; Private Static final float rate_min = 8; Private Static final float rate_max = 12; Private Static final int participant s_max = 200;
// ================================================ ====================================/// Fields // ====================== ========================================================== =====
Private camera mcamera; private bitmaptextureatlas mbitmaptextureatlas; private itextureregion mparticletextureregion;
// ================================================ ====================================/// Constructors // ======================== ========================================================== =====
// ================================================ ==================================/// Getter & setter // ================== ========================================================== ========
// ================================================ ====================================/// Methods for/from superclass/interfaces // ========== ========================================================== ==============
@ Override public engineoptions oncreateengineoptions () {This. mcamera = new camera (0, 0, participant systemnexusexample. camera_width, participant systemnexusexample. camera_height );
Return new engineoptions (true, screenorientation. landscape_fixed, new ratioresolutionpolicy (participant systemnexusexample. camera_width, participant systemnexusexample. camera_height), this. mcamera );}
@ Override protected void oncreateresources () {bitmaptextureatlastextureregionfactory. setassetbasepath ("GFX /");
This. mbitmaptextureatlas = new bitmaptextureatlas (this. gettexturemanager (), 32, 32, textureoptions. bilinear_premultiplyalpha); this. mparticletextureregion = bitmaptextureatlastextureregionfactory. createfromasset (this. mbitmaptextureatlas, this, "maid", 0, 0 );
This. mengine. gettexturemanager (). loadtexture (this. mbitmaptextureatlas );}
@ Override protected scene oncreatescene () {This. mengine. registerupdatehandler (New fpslogger ());
Final scene = new scene (); scene. setbackground (new background (0.0f, 0.0f, 0.0f ));
/* Lowerleft to lowerright particle system. */{final spriteparticlesystem particle system = new spriteparticlesystem (New pointparticle emitter (-32, particle systemnexusexample. camera_height-32), fig. rate_min, fig. rate_max, fig. participant s_max, this. mparticletextureregion, this. getvertexbufferobjectmanager (); participant system. addparticipant leinitializer (New blendfunctionparticipant leinitializer <sprite> (gles1_gl _ src_alpha, gles1_gl _ One); participant system. addparticle initializer (New velocityparticle initializer <sprite> (35, 45, 0,-10); particle system. addparticipant leinitializer (New accelerationparticipant leinitializer <sprite> (5,-11); participant system. addparticle initializer (New rotationparticle initializer <sprite> (0.0f, 360.0f); particle system. addparticle initializer (New colorparticle initializer <sprite> (1.0f, 1.0f, 0.0f); particle system. addparticipant leinitializer (New expireparticipant leinitializer <sprite> (6.5f ));
Particle System. addparticle modifier (New scaleparticlemodifier <sprite> (0, 5, 0.5f, 2.0f); particle system. addparticipant lemodifier (New colorparticipant lemodifier <sprite> (2.5f, 5.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f); participant system. addparticipant lemodifier (New alphaparticlemodifier <sprite> (2.5f, 6.5f, 1.0f, 0.0f ));
Scene. attachchild (participant system );}
/* Lowerright to lowerleft particle system. */{final spriteparticlesystem particle system = new spriteparticlesystem (New pointparticle emitter (particle systemnexusexample. camera_width, fig. camera_height-32), fig. rate_min, fig. rate_max, fig. participant s_max, this. mparticletextureregion, this. getvertexbufferobjectmanager (); participant system. addparticipant leinitializer (New blendfunctionparticipant leinitializer <sprite> (gles1_gl _ src_alpha, gles1_gl _ One); participant system. addparticle initializer (New velocityparticle initializer <sprite> (-35,-45, 0,-10); particle system. addparticle initializer (New accelerationparticle initializer <sprite> (-5,-11); particle system. addparticle initializer (New rotationparticle initializer <sprite> (0.0f, 360.0f); particle system. addparticle initializer (New colorparticle initializer <sprite> (0.0f, 1.0f, 0.0f); particle system. addparticipant leinitializer (New expireparticipant leinitializer <sprite> (6.5f ));
Particle System. addparticle modifier (New scaleparticlemodifier <sprite> (0, 5, 0.5f, 2.0f); particle system. addparticle modifier (New colorparticle modifier <sprite> (2.5f, 5.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f); particle system. addparticipant lemodifier (New alphaparticlemodifier <sprite> (2.5f, 6.5f, 1.0f, 0.0f ));
Scene. attachchild (participant system );}
/* Upperleft to upperright particle system. */{final spriteparticlesystem particle system = new spriteparticlesystem (New pointparticipant emitter (-32, 0), and participant systemnexusexample. rate_min, fig. rate_max, fig. participant s_max, this. mparticletextureregion, this. getvertexbufferobjectmanager (); participant system. addparticipant leinitializer (New blendfunctionparticipant leinitializer <sprite> (gles1_gl _ src_alpha, gles1_gl _ One); participant system. addparticle initializer (New velocityparticle initializer <sprite> (35, 45, 0, 10); particle system. addparticipant leinitializer (New accelerationparticipant leinitializer <sprite> (5, 11); participant system. addparticle initializer (New rotationparticle initializer <sprite> (0.0f, 360.0f); particle system. addparticle initializer (New colorparticle initializer <sprite> (0.0f, 0.0f, 1.0f); particle system. addparticipant leinitializer (New expireparticipant leinitializer <sprite> (6.5f ));
Particle System. addparticle modifier (New scaleparticlemodifier <sprite> (0, 5, 0.5f, 2.0f); particle system. addparticle modifier (New colorparticle modifier <sprite> (2.5f, 5.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f); particle system. addparticipant lemodifier (New alphaparticlemodifier <sprite> (2.5f, 6.5f, 1.0f, 0.0f ));
Scene. attachchild (participant system );}
/* Upperright to upperleft particle system. */{final spriteparticlesystem particle system = new spriteparticlesystem (New pointparticle emitter (particle systemnexusexample. camera_width, 0), fig. rate_min, fig. rate_max, fig. participant s_max, this. mparticletextureregion, this. getvertexbufferobjectmanager (); participant system. addparticipant leinitializer (New blendfunctionparticipant leinitializer <sprite> (gles1_gl _ src_alpha, gles1_gl _ One); participant system. addparticle initializer (New velocityparticle initializer <sprite> (-35,-45, 0, 10); particle system. addparticipant leinitializer (New accelerationparticipant leinitializer <sprite> (-5, 11); participant system. addparticle initializer (New rotationparticle initializer <sprite> (0.0f, 360.0f); particle system. addparticle initializer (New colorparticle initializer <sprite> (1.0f, 0.0f, 0.0f); particle system. addparticipant leinitializer (New expireparticipant leinitializer <sprite> (6.5f ));
Particle System. addparticle modifier (New scaleparticlemodifier <sprite> (0, 5, 0.5f, 2.0f); particle system. addparticle modifier (New colorparticle modifier <sprite> (2.5f, 5.5f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); particle system. addparticipant lemodifier (New alphaparticlemodifier <sprite> (2.5f, 6.5f, 1.0f, 0.0f ));
Scene. attachchild (participant system );}
Return scene ;}
// ================================================ ======================================/// Methods // ========================================================== =====
// ================================================ ======================================/Inner and anonymous classes // ================ ========================================================== =======}
// The effect of this Code is to achieve a non-circular flame burning effect at the four corners of the mobile phone screen. The first difference is: ": defines four particle systems, at the same time, each system has its own particle transmitter: pointparticle emitter. We can find that it is different from the previous particle (circleoutlineparticleemitter. Finally, the four particle systems are added to the scenario. At this point, everything is OK.