1
+ package org .andengine .examples ;
2
+
3
+ import org .andengine .engine .camera .Camera ;
4
+ import org .andengine .engine .options .EngineOptions ;
5
+ import org .andengine .engine .options .EngineOptions .ScreenOrientation ;
6
+ import org .andengine .engine .options .resolutionpolicy .RatioResolutionPolicy ;
7
+ import org .andengine .entity .particle .SpriteParticleSystem ;
8
+ import org .andengine .entity .particle .emitter .CircleOutlineParticleEmitter ;
9
+ import org .andengine .entity .particle .initializer .AlphaParticleInitializer ;
10
+ import org .andengine .entity .particle .initializer .BlendFunctionParticleInitializer ;
11
+ import org .andengine .entity .particle .initializer .ColorParticleInitializer ;
12
+ import org .andengine .entity .particle .initializer .RotationParticleInitializer ;
13
+ import org .andengine .entity .particle .initializer .VelocityParticleInitializer ;
14
+ import org .andengine .entity .particle .modifier .AlphaParticleModifier ;
15
+ import org .andengine .entity .particle .modifier .ColorParticleModifier ;
16
+ import org .andengine .entity .particle .modifier .ExpireParticleModifier ;
17
+ import org .andengine .entity .particle .modifier .ScaleParticleModifier ;
18
+ import org .andengine .entity .scene .Scene ;
19
+ import org .andengine .entity .scene .Scene .IOnSceneTouchListener ;
20
+ import org .andengine .entity .sprite .Sprite ;
21
+ import org .andengine .entity .util .FPSLogger ;
22
+ import org .andengine .input .touch .TouchEvent ;
23
+ import org .andengine .opengl .texture .TextureOptions ;
24
+ import org .andengine .opengl .texture .atlas .bitmap .BitmapTextureAtlas ;
25
+ import org .andengine .opengl .texture .atlas .bitmap .BitmapTextureAtlasTextureRegionFactory ;
26
+ import org .andengine .opengl .texture .region .ITextureRegion ;
27
+ import org .andengine .ui .activity .SimpleLayoutGameActivity ;
28
+
29
+ import android .opengl .GLES20 ;
30
+ import android .widget .Toast ;
31
+
32
+ /**
33
+ * (c) 2010 Nicolas Gramlich
34
+ * (c) 2011 Zynga
35
+ *
36
+ * @author Nicolas Gramlich
37
+ * @since 11:54:51 - 03.04.2010
38
+ */
39
+ public class XMLLayoutExample extends SimpleLayoutGameActivity {
40
+ // ===========================================================
41
+ // Constants
42
+ // ===========================================================
43
+
44
+ private static final int CAMERA_WIDTH = 720 ;
45
+ private static final int CAMERA_HEIGHT = 480 ;
46
+
47
+ // ===========================================================
48
+ // Fields
49
+ // ===========================================================
50
+
51
+ private BitmapTextureAtlas mBitmapTextureAtlas ;
52
+ private ITextureRegion mParticleTextureRegion ;
53
+
54
+ // ===========================================================
55
+ // Constructors
56
+ // ===========================================================
57
+
58
+ // ===========================================================
59
+ // Getter & Setter
60
+ // ===========================================================
61
+
62
+ // ===========================================================
63
+ // Methods for/from SuperClass/Interfaces
64
+ // ===========================================================
65
+
66
+ @ Override
67
+ protected int getLayoutID () {
68
+ return R .layout .xmllayoutexample ;
69
+ }
70
+
71
+ @ Override
72
+ protected int getRenderSurfaceViewID () {
73
+ return R .id .xmllayoutexample_rendersurfaceview ;
74
+ }
75
+
76
+ @ Override
77
+ public EngineOptions onCreateEngineOptions () {
78
+ Toast .makeText (this , "Touch the screen to move the particlesystem." , Toast .LENGTH_LONG ).show ();
79
+
80
+ final Camera camera = new Camera (0 , 0 , XMLLayoutExample .CAMERA_WIDTH , XMLLayoutExample .CAMERA_HEIGHT );
81
+
82
+ return new EngineOptions (true , ScreenOrientation .LANDSCAPE_FIXED , new RatioResolutionPolicy (XMLLayoutExample .CAMERA_WIDTH , XMLLayoutExample .CAMERA_HEIGHT ), camera );
83
+ }
84
+
85
+ @ Override
86
+ protected void onCreateResources () {
87
+ BitmapTextureAtlasTextureRegionFactory .setAssetBasePath ("gfx/" );
88
+
89
+ this .mBitmapTextureAtlas = new BitmapTextureAtlas (this .getTextureManager (), 32 , 32 , TextureOptions .BILINEAR );
90
+
91
+ this .mParticleTextureRegion = BitmapTextureAtlasTextureRegionFactory .createFromAsset (this .mBitmapTextureAtlas , this , "particle_point.png" , 0 , 0 );
92
+
93
+ this .mBitmapTextureAtlas .load ();
94
+ }
95
+
96
+ @ Override
97
+ protected Scene onCreateScene () {
98
+ this .mEngine .registerUpdateHandler (new FPSLogger ());
99
+
100
+ final Scene scene = new Scene ();
101
+
102
+ final CircleOutlineParticleEmitter particleEmitter = new CircleOutlineParticleEmitter (XMLLayoutExample .CAMERA_WIDTH * 0.5f , (XMLLayoutExample .CAMERA_HEIGHT * 0.5f ) + 20 , 80 );
103
+ final SpriteParticleSystem particleSystem = new SpriteParticleSystem (particleEmitter , 60 , 60 , 360 , this .mParticleTextureRegion , this .getVertexBufferObjectManager ());
104
+
105
+ scene .setOnSceneTouchListener (new IOnSceneTouchListener () {
106
+ @ Override
107
+ public boolean onSceneTouchEvent (final Scene pScene , final TouchEvent pSceneTouchEvent ) {
108
+ particleEmitter .setCenter (pSceneTouchEvent .getX (), pSceneTouchEvent .getY ());
109
+ return true ;
110
+ }
111
+ });
112
+
113
+ particleSystem .addParticleInitializer (new ColorParticleInitializer <Sprite >(1 , 0 , 0 ));
114
+ particleSystem .addParticleInitializer (new AlphaParticleInitializer <Sprite >(0 ));
115
+ particleSystem .addParticleInitializer (new BlendFunctionParticleInitializer <Sprite >(GLES20 .GL_SRC_ALPHA , GLES20 .GL_ONE ));
116
+ particleSystem .addParticleInitializer (new VelocityParticleInitializer <Sprite >(-2 , 2 , -20 , -10 ));
117
+ particleSystem .addParticleInitializer (new RotationParticleInitializer <Sprite >(0.0f , 360.0f ));
118
+
119
+ particleSystem .addParticleModifier (new ScaleParticleModifier <Sprite >(0 , 5 , 1.0f , 2.0f ));
120
+ particleSystem .addParticleModifier (new ColorParticleModifier <Sprite >(0 , 3 , 1 , 1 , 0 , 0.5f , 0 , 0 ));
121
+ particleSystem .addParticleModifier (new ColorParticleModifier <Sprite >(4 , 6 , 1 , 1 , 0.5f , 1 , 0 , 1 ));
122
+ particleSystem .addParticleModifier (new AlphaParticleModifier <Sprite >(0 , 1 , 0 , 1 ));
123
+ particleSystem .addParticleModifier (new AlphaParticleModifier <Sprite >(5 , 6 , 1 , 0 ));
124
+ particleSystem .addParticleModifier (new ExpireParticleModifier <Sprite >(6 ));
125
+
126
+ scene .attachChild (particleSystem );
127
+
128
+ return scene ;
129
+ }
130
+
131
+ // ===========================================================
132
+ // Methods
133
+ // ===========================================================
134
+
135
+ // ===========================================================
136
+ // Inner and Anonymous Classes
137
+ // ===========================================================
138
+ }
0 commit comments