Fixed touch events and Window, also new onTouchReal events - which retain the proper...
[rokon:rokon.git] / src / com / stickycoding / rokon / Scene.java
1 package com.stickycoding.rokon;\r
2 \r
3 import java.lang.reflect.InvocationTargetException;\r
4 import java.lang.reflect.Method;\r
5 import java.util.Arrays;\r
6 \r
7 import javax.microedition.khronos.opengles.GL10;\r
8 \r
9 import android.view.KeyEvent;\r
10 import android.view.MotionEvent;\r
11 \r
12 import com.badlogic.gdx.physics.box2d.Contact;\r
13 import com.badlogic.gdx.physics.box2d.ContactListener;\r
14 import com.badlogic.gdx.physics.box2d.World;\r
15 import com.stickycoding.rokon.device.Graphics;\r
16 \r
17 /**\r
18  * Scene.java\r
19  * A Scene holds and prepares drawable objects or object groups\r
20  * \r
21  * @author Richard\r
22  */\r
23 public class Scene {\r
24         \r
25         public static final int SCENE_TEXTURE_COUNT = 32;\r
26         public static final int DEFAULT_LAYER_COUNT = 1;\r
27         public static final int DEFAULT_LAYER_OBJECT_COUNT = 32;\r
28 \r
29         protected Layer[] layer;\r
30         protected boolean loadedTextures;\r
31         protected int layerCount;\r
32         protected Window window = null;\r
33         protected Texture[] texturesToLoad;\r
34         protected Texture[] texturesOnHardware;\r
35         protected boolean useInvoke;\r
36         protected World world;\r
37         protected boolean usePhysics = false;\r
38         protected ContactListener contactListener;\r
39         protected boolean useContactListener;\r
40 \r
41         public void onPreDraw(GL10 gl) { }\r
42         public void onPostDraw(GL10 gl) { }\r
43         \r
44         public void onTouchDown(DrawableObject object, float x, float y, MotionEvent event) { }\r
45         public void onTouchUp(DrawableObject object, float x, float y, MotionEvent event) { }\r
46         public void onTouchMove(DrawableObject object, float x, float y, MotionEvent event) { }\r
47         public void onTouch(DrawableObject object, float x, float y, MotionEvent event) { }\r
48         public void onTouchDown(float x, float y, MotionEvent event) { }\r
49         public void onTouchMove(float x, float y, MotionEvent event) { }\r
50         public void onTouch(float x, float y, MotionEvent event) { }\r
51         public void onTouchUp(float x, float y, MotionEvent event) { }\r
52         \r
53         public void onTouchDownReal(float x, float y, MotionEvent event) { }\r
54         public void onTouchMoveReal(float x, float y, MotionEvent event) { }\r
55         public void onTouchUpReal(float x, float y, MotionEvent event) { }\r
56         public void onTouchReal(float x, float y, MotionEvent event) { }\r
57         \r
58         public void onKeyDown(int keyCode, KeyEvent event) { }\r
59         \r
60         /**\r
61          * Sets a World for the physics in this Scene\r
62          * Automatically flags usePhysics\r
63          * \r
64          * @param world valid World object\r
65          */\r
66         public void setWorld(World world) {\r
67                 this.world = world;\r
68                 Physics.world = world;\r
69                 usePhysics = true;\r
70         }\r
71         \r
72         /**\r
73          * Returns the World associated with this Scene\r
74          * \r
75          * @return NULL if no World set\r
76          */\r
77         public World getWorld() {\r
78                 return world;\r
79         }\r
80         \r
81         /**\r
82          * Flags to use physics in this Scene\r
83          */\r
84         public void usePhysics() {\r
85                 usePhysics = true;\r
86         }\r
87         \r
88         /**\r
89          * Flags to not use physics\r
90          */\r
91         public void noPhysics() {\r
92                 usePhysics = false;\r
93         }\r
94         \r
95         /**\r
96          * Removes the World from this Scene\r
97          */\r
98         public void removeWorld() {\r
99                 this.world = null;\r
100                 Physics.world = null;\r
101                 usePhysics = false;\r
102         }\r
103         \r
104         /**\r
105          * Triggers the Scene to begin invoking methods on certain events, this is not set by default.\r
106          * If the methods that are to be invoked don't exist, no exceptions will be raised.\r
107          */\r
108         public void useInvoke() {\r
109                 useInvoke = true;\r
110         }\r
111         \r
112         /**\r
113          * Stops the Scene from invoking methods on events, this is the default state\r
114          */\r
115         public void stopInvoke() {\r
116                 useInvoke = false;\r
117         }\r
118         \r
119         /**\r
120          * Invokes a method inside the Scene class, defined by given parameters.\r
121          * If no parameters exist, use the alternative invoke method\r
122          * \r
123          * @param methodName String\r
124          * @param params Class[]\r
125          * @param paramValues Object[]\r
126          * \r
127          * @return TRUE if successful, FALSE otherwise\r
128          */\r
129         public boolean invoke(String methodName, Class<?>[] params, Object[] paramValues) {\r
130                 for(Method m : this.getClass().getDeclaredMethods()) {\r
131                         if(m.getName().equals(methodName)) {\r
132                                 if(Arrays.equals(params, m.getParameterTypes())) {\r
133                                         try {\r
134                                                 m.invoke(this, paramValues);\r
135                                                 return true;\r
136                                         } catch (IllegalArgumentException e) {\r
137                                                 Debug.error("Invoking, IllegalArgument");\r
138                                                 e.printStackTrace();\r
139                                                 return false;\r
140                                         } catch (IllegalAccessException e) {\r
141                                                 Debug.error("Invoking, IllegalAccess");\r
142                                                 e.printStackTrace();\r
143                                                 return false;\r
144                                         } catch (InvocationTargetException e) {\r
145                                                 Debug.error("Invoking, IllegalTarget");\r
146                                                 e.printStackTrace();\r
147                                                 return false;\r
148                                         }\r
149                                 }\r
150                         }\r
151                 }\r
152                 return false;\r
153         }\r
154         \r
155         /**\r
156          * Invokes a method by parameters inside a Callback object\r
157          * \r
158          * @param callback valid Callback object\r
159          * @return TRUE if successful, FALSE otherwise\r
160          */\r
161         public boolean invoke(Callback callback) {\r
162                 if(callback.parameters == null) {\r
163                         return invoke(callback.methodName);\r
164                 } \r
165                 if(callback.parameterTypes == null) {\r
166                         return invoke(callback.methodName, callback.parameters);\r
167                 }\r
168                 return invoke(callback.methodName, callback.parameterTypes, callback.parameters);\r
169         }\r
170         \r
171         /**\r
172          * USE AT YOUR OWN RISK\r
173          * Invokes a method inside the Scene class, it selects the first matching method name and tries to pass on given parameters\r
174          * An error will be raised if this isn't the correct method. This routine is simply for those too lazy (or wanting to save\r
175          * on a little processing time) and are 100% sure there are no name conflicts.\r
176          * \r
177          * IllegalArgumentException may be passed to the Debug class, logcat will be notified - but there is no way to test at your end.\r
178          * \r
179          * @param methodName String\r
180          * @param paramValues Object[]\r
181          * \r
182          * @return TRUE if successful, FALSE otherwise\r
183          */\r
184         public boolean invoke(String methodName, Object[] paramValues) {\r
185                 for(Method m : this.getClass().getDeclaredMethods()) {\r
186                         if(m.getName().equals(methodName)) {\r
187                                 try {\r
188                                         m.invoke(this, paramValues);\r
189                                         return true;\r
190                                 } catch (IllegalArgumentException e) {\r
191                                         Debug.error("Invoking, IllegalArgument");\r
192                                         e.printStackTrace();\r
193                                         return false;\r
194                                 } catch (IllegalAccessException e) {\r
195                                         Debug.error("Invoking, IllegalAccess");\r
196                                         e.printStackTrace();\r
197                                         return false;\r
198                                 } catch (InvocationTargetException e) {\r
199                                         Debug.error("Invoking, IllegalTarget");\r
200                                         e.printStackTrace();\r
201                                         return false;\r
202                                 }\r
203                         }\r
204                 }\r
205                 return false;\r
206         }\r
207         \r
208         /**\r
209          * Invokes a method inside the Scene class, assuming there are no parameters to pass\r
210          * \r
211          * @param methodName String\r
212          * \r
213          * @return TRUE if successful, FALSE otherwise\r
214          */\r
215         public boolean invoke(String methodName) {\r
216                 for(Method m : this.getClass().getDeclaredMethods()) {\r
217                         if(m.getName().equals(methodName)) {\r
218                                 if(m.getParameterTypes().length == 0) {\r
219                                         try {\r
220                                                 m.invoke(this);\r
221                                                 return true;\r
222                                         } catch (IllegalArgumentException e) {\r
223                                                 Debug.error("Invoking, IllegalArgument");\r
224                                                 e.printStackTrace();\r
225                                                 return false;\r
226                                         } catch (IllegalAccessException e) {\r
227                                                 Debug.error("Invoking, IllegalAccess");\r
228                                                 e.printStackTrace();\r
229                                                 return false;\r
230                                         } catch (InvocationTargetException e) {\r
231                                                 Debug.error("Invoking, IllegalTarget");\r
232                                                 e.printStackTrace();\r
233                                                 return false;\r
234                                         }\r
235                                 }\r
236                         }\r
237                 }\r
238                 return false;\r
239         }\r
240         \r
241         protected void handleTouch(MotionEvent event) {\r
242                 float realX = event.getX() * (Graphics.getWidthPixels() / RokonActivity.gameWidth);\r
243                 float realY = event.getY() * (Graphics.getHeightPixels() / RokonActivity.gameHeight);\r
244                 if(window != null) {\r
245                         float xFraction = event.getX() / Graphics.getWidthPixels();\r
246                         float yFraction = event.getY() / Graphics.getHeightPixels();\r
247                         float gameX = window.x + (window.width * xFraction);\r
248                         float gameY = window.y + (window.height * yFraction);\r
249                         event.setLocation(gameX, gameY);\r
250                 } else {\r
251                         event.setLocation(event.getX() * (Graphics.getWidthPixels() / RokonActivity.gameWidth), event.getY() * (Graphics.getHeightPixels()  / RokonActivity.gameHeight));                       \r
252                 }\r
253                 onTouch(event.getX(), event.getY(), event);\r
254                 onTouchReal(realX, realY, event);\r
255                 switch(event.getAction()) {\r
256                         case MotionEvent.ACTION_DOWN:\r
257                                 onTouchDown(event.getX(), event.getY(), event);\r
258                                 onTouchDownReal(realX, realY, event);\r
259                                 break;\r
260                         case MotionEvent.ACTION_UP:\r
261                                 onTouchUp(event.getX(), event.getY(), event);\r
262                                 onTouchUpReal(realX, realY, event);\r
263                                 break;\r
264                         case MotionEvent.ACTION_MOVE:\r
265                                 onTouch(event.getX(), event.getY(), event);\r
266                                 onTouchUp(realX, realY, event);\r
267                                 break;\r
268                 }\r
269                 for(int i = 0; i < layerCount; i++) {\r
270                         for(int j = 0; j < layer[i].maximumDrawableObjects; j++) {\r
271                                 DrawableObject object = layer[i].drawableObjects.get(j);\r
272                                 if(object != null && object.isTouchable) {\r
273                                         if(MathHelper.pointInRect(event.getX(), event.getY(), object.x, object.y, object.width, object.height)) {\r
274                                                 onTouch(object, event.getX(), event.getY(), event);\r
275                                                 if(object.getName() != null) {\r
276                                                         invoke(object.getName() + "_onTouch", new Class[] { float.class, float.class, MotionEvent.class }, new Object[] { event.getX(), event.getY(), event });\r
277                                                 }\r
278                                                 switch(event.getAction()) {\r
279                                                         case MotionEvent.ACTION_DOWN:\r
280                                                                 onTouchDown(object, event.getX(), event.getY(), event);\r
281                                                                 if(object.getName() != null) {\r
282                                                                         invoke(object.getName() + "_onTouchDown", new Class[] { float.class, float.class, MotionEvent.class }, new Object[] { event.getX(), event.getY(), event });\r
283                                                                 }\r
284                                                                 break;\r
285                                                         case MotionEvent.ACTION_UP:\r
286                                                                 onTouchUp(object, event.getX(), event.getY(), event);\r
287                                                                 if(object.getName() != null) {\r
288                                                                         invoke(object.getName() + "_onTouchUp", new Class[] { float.class, float.class, MotionEvent.class }, new Object[] { event.getX(), event.getY(), event });\r
289                                                                 }\r
290                                                                 break;\r
291                                                         case MotionEvent.ACTION_MOVE:\r
292                                                                 onTouch(object, event.getX(), event.getY(), event);\r
293                                                                 if(object.getName() != null) {\r
294                                                                         invoke(object.getName() + "_onTouchMove", new Class[] { float.class, float.class, MotionEvent.class }, new Object[] { event.getX(), event.getY(), event });\r
295                                                                 }\r
296                                                                 break;\r
297                                                 }\r
298                                         }\r
299                                 }\r
300                         }\r
301                 }\r
302         }\r
303         \r
304         /**\r
305          * Creates a new Scene with given layer count, and a corresponding maximum DrawableObject count \r
306          * \r
307          * @param layerCount maximum number of layers\r
308          * @param layerObjectCount maximum number of DrawableObjects per layer, the array length must match layerCount\r
309          */\r
310         public Scene(int layerCount, int[] layerObjectCount) {\r
311                 this.layerCount = layerCount;\r
312                 layer = new Layer[layerCount];\r
313                 for(int i = 0; i < layerCount; i++) {\r
314                         layer[i] = new Layer(this, layerObjectCount[i]);\r
315                 }\r
316                 prepareNewScene();\r
317         }\r
318         \r
319         /**\r
320          * Creates a new Scene with given layer count, all layers will have the same maximum number of DrawableObjects\r
321          * \r
322          * @param layerCount maximum number of layers\r
323          * @param layerObjectCount maximum number of DrawableObjects per layer\r
324          */\r
325         public Scene(int layerCount, int layerObjectCount) {\r
326                 this.layerCount = layerCount;\r
327                 layer = new Layer[layerCount];\r
328                 for(int i = 0; i < layerCount; i++) {\r
329                         layer[i] = new Layer(this, layerObjectCount);\r
330                 }\r
331                 prepareNewScene();\r
332         }\r
333         \r
334         /**\r
335          * Creates a new Scene with given layer count, and a default maximum DrawableObject count of DEFAULT_LAYER_OBJECT_COUNT\r
336          * \r
337          * @param layerCount maximum number of layers\r
338          */\r
339         public Scene(int layerCount) {\r
340                 this(layerCount, DEFAULT_LAYER_OBJECT_COUNT);\r
341         }\r
342         \r
343         /**\r
344          * Creates a new Scene with defaults, DEFAULT_LAYER_COUNT and DEFAULT_LAYER_OBJECT_COUNT\r
345          */\r
346         public Scene() {\r
347                 this(DEFAULT_LAYER_COUNT, DEFAULT_LAYER_OBJECT_COUNT);\r
348                 \r
349         }\r
350         \r
351         private void prepareNewScene() {\r
352                 texturesToLoad = new Texture[SCENE_TEXTURE_COUNT];\r
353                 texturesOnHardware = new Texture[SCENE_TEXTURE_COUNT];\r
354         }\r
355         \r
356         /**\r
357          * Flags a Texture to be loaded into this Scene\r
358          * This must be called before RokonActivity.setScene\r
359          * \r
360          * @param texture valid Texture object\r
361          */\r
362         public void useTexture(Texture texture) {\r
363                 for(int i = 0; i < texturesToLoad.length; i++) {\r
364                         if(texturesToLoad[i] == texture) return;\r
365                         if(texturesToLoad[i] == null) {\r
366                                 texturesToLoad[i] = texture;\r
367                                 return;\r
368                         }\r
369                 }\r
370                 Debug.warning("Scene.useTexture", "Tried loading too many Textures onto the Scene, max is " + texturesToLoad.length);\r
371         }\r
372         \r
373         /**\r
374          * Defines the active Window for this Scene\r
375          * If no Window is given, a default static view will be rendered \r
376          * \r
377          * @param window\r
378          */\r
379         public void setWindow(Window window) {\r
380                 if(window == null) {\r
381                         Debug.warning("Scene.setWindow", "Tried setting a NULL Window");\r
382                         return;\r
383                 }\r
384                 this.window = window;\r
385         }\r
386         \r
387         /**\r
388          * Removes the current active Window, returning it to NULL\r
389          */\r
390         public void removeWindow() {\r
391                 window = null;\r
392         }\r
393         \r
394         /**\r
395          * @return NULL if there is no Window associated with this Scene\r
396          */\r
397         public Window getWindow() {\r
398                 if(window == null)\r
399                         return null;\r
400                 return window;\r
401         }\r
402         \r
403         /**\r
404          * Fetches the Layer object associated with the given index\r
405          * \r
406          * @param index the index of the Layer\r
407          * @return NULL if invalid index is given\r
408          */\r
409         public Layer getLayer(int index) {\r
410                 if(index < 0 || index > layerCount) {\r
411                         Debug.warning("Scene.getLayer", "Tried fetching invalid layer (" + index + "), maximum is " + layerCount);\r
412                         return null;\r
413                 }\r
414                 return layer[index];\r
415         }\r
416         \r
417         /**\r
418          * Clears the DrawableObjects from all Layers\r
419          */\r
420         public void clear() {\r
421                 for(int i = 0; i < layerCount; i++) {\r
422                         layer[i].clear();\r
423                 }\r
424         }\r
425         \r
426         /**\r
427          * Clears all the DrawableObjects from a specified Layer\r
428          * \r
429          * @param index the index of the Layer\r
430          */\r
431         public void clearLayer(int index) {\r
432                 if(index <= 0 || index > layerCount) {\r
433                         Debug.warning("Scene.clearLayer", "Tried clearing invalid layer (" + index + "), maximum is " + layerCount);\r
434                         return;\r
435                 }\r
436                 layer[index].clear();\r
437         }\r
438         \r
439         /**\r
440          * Moves a Layer from one index to another, and shuffles the others up or down to accomodate\r
441          * \r
442          * @param startIndex the current index of the Layer\r
443          * @param endIndex the desired final index of the Layer\r
444          */\r
445         public void moveLayer(int startIndex, int endIndex) {\r
446                 if(startIndex == endIndex) {\r
447                         Debug.warning("Scene.moveLayer", "Tried moving a Layer to its own position, stupid");\r
448                         return;\r
449                 }\r
450                 if(startIndex <= 0 || startIndex > layerCount) {\r
451                         Debug.warning("Scene.moveLayer", "Tried moving an invalid Layer, startIndex=" + startIndex + ", maximum is " + layerCount);\r
452                         return;\r
453                 }\r
454                 if(endIndex <= 0 || endIndex > layerCount) {\r
455                         Debug.warning("Scene.moveLayer", "Tried moving an invalid Layer, endIndex=" + endIndex + ", maximum is " + layerCount);\r
456                         return;\r
457                 }\r
458                 Layer temporaryLayer = layer[startIndex];\r
459                 if(endIndex < startIndex) {\r
460                         for(int i = endIndex; i < startIndex; i++) {\r
461                                 layer[i + 1] = layer[i];\r
462                         }\r
463                         layer[endIndex] = temporaryLayer;\r
464                 }\r
465                 if(endIndex > startIndex) { \r
466                         for(int i = startIndex; i < endIndex; i++) {\r
467                                 layer[i] = layer[i + 1];\r
468                         }\r
469                         layer[endIndex] = temporaryLayer;\r
470                 }\r
471         }\r
472         \r
473         /**\r
474          * Switches the position of one Layer with another\r
475          * \r
476          * @param layer1 the index of the first Layer\r
477          * @param layer2 the index of the second Layer\r
478          */\r
479         public void switchLayers(int layer1, int layer2) {\r
480                 if(layer1 == layer2) {\r
481                         Debug.warning("Scene.switchLayers", "Tried switching the same Layer");\r
482                         return;\r
483                 }\r
484                 if(layer1 < 0 || layer1 > layerCount) {\r
485                         Debug.warning("Scene.switchLayers", "Tried switch an invalid Layer, layer1=" + layer1 + ", maximum is " + layerCount);\r
486                         return;\r
487                 }\r
488                 if(layer2 < 0 || layer2 > layerCount) {\r
489                         Debug.warning("Scene.switchLayers", "Tried switch an invalid Layer, layer2=" + layer2 + ", maximum is " + layerCount);\r
490                         return;\r
491                 }\r
492                 Layer temporaryLayer = layer[layer1];\r
493                 layer[layer1] = layer[layer2];\r
494                 layer[layer2] = temporaryLayer;\r
495         }\r
496         \r
497         /**\r
498          * Replaces a Layer object in this Scene\r
499          * \r
500          * @param index a valid index for a Layer, less than getLayerCount\r
501          * @param layer a valid Layer object to replace the existing Layer\r
502          */\r
503         public void setLayer(int index, Layer layer) {\r
504                 if(layer == null) {\r
505                         Debug.warning("Scene.setLayer", "Tried setting to a null Layer");\r
506                         return;\r
507                 }\r
508                 if(index < 0 || index > layerCount) {\r
509                         Debug.warning("Scene.setLayer", "Tried setting an invalid Layer, index=" + index + ", maximum is " + layerCount);\r
510                         return;\r
511                 }\r
512                 this.layer[index] = layer;\r
513         }\r
514         \r
515         /**\r
516          * Adds a DrawableObject to the first (0th) Layer\r
517          * \r
518          * @param drawableObject a valid DrawableObject\r
519          */\r
520         public void add(DrawableObject drawableObject) {\r
521                 layer[0].add(drawableObject);\r
522         }\r
523         \r
524         /**\r
525          * Adds a DrawableObject to a given Layer\r
526          * \r
527          * @param layerIndex a valid index of a Layer\r
528          * @param drawableObject a valid DrawableObject\r
529          */\r
530         public void add(int layerIndex, DrawableObject drawableObject) {\r
531                 if(layerIndex < 0 || layerIndex > layerCount) {\r
532                         Debug.warning("Scene.add", "Tried adding to an invalid Layer, layerIndex=" + layerIndex + ", maximum is " + layerCount);\r
533                         return;\r
534                 }\r
535                 if(drawableObject == null) {\r
536                         Debug.warning("Scene.add", "Tried adding a NULL DrawableObject");\r
537                         return;\r
538                 }\r
539                 layer[layerIndex].add(drawableObject);\r
540         }\r
541         \r
542         /**\r
543          * Removes a DrawableObject from the Scene\r
544          * \r
545          * @param drawableObject a valid DrawableObject\r
546          */\r
547         public void remove(DrawableObject drawableObject) {\r
548                 drawableObject.remove();\r
549         }\r
550         \r
551         protected void onUpdate() {\r
552                 \r
553         }\r
554         \r
555         protected void onGameLoop() {\r
556                 \r
557         }\r
558         \r
559         protected void onSetScene() {\r
560                 loadedTextures = false;\r
561         }\r
562         \r
563         protected void onEndScene() {\r
564                 \r
565         }\r
566         \r
567         protected void onLoadTextures(GL10 gl) {\r
568                 Debug.print("Loading textures onto the Scene");\r
569                 for(int i = 0; i < texturesToLoad.length; i++) {\r
570                         if(texturesToLoad[i] != null) {\r
571                                 texturesToLoad[i].onLoadTexture(gl);\r
572                                 boolean foundSpace = false;\r
573                                 for(int j = 0; j < texturesOnHardware.length; j++) {\r
574                                         if(texturesOnHardware[j] == null) {\r
575                                                 Debug.print("found room...");\r
576                                                 texturesOnHardware[j] = texturesToLoad[i];\r
577                                                 foundSpace = true;\r
578                                                 break;\r
579                                         }\r
580                                 }\r
581                                 if(!foundSpace) {\r
582                                         Debug.warning("Loading more textures than we can remember - will not be there if we onPause, may not be destroyed on Scene death");\r
583                                 }\r
584                                 texturesToLoad[i] = null;\r
585                         }\r
586                 }\r
587                 loadedTextures = true;\r
588         }\r
589         \r
590         protected void onReloadTextures(GL10 gl) {\r
591                 texturesToLoad = texturesOnHardware;\r
592                 for(int i = 0; i < texturesOnHardware.length; i++) {\r
593                         texturesOnHardware[i] = null;\r
594                 }\r
595                 onLoadTextures(gl);\r
596         }\r
597         \r
598         protected void onDraw(GL10 gl) {\r
599                 if(window != null) {\r
600                         window.onUpdate(gl);\r
601                 }\r
602                 onPreDraw(gl);\r
603                 if(usePhysics && !pausePhysics) {\r
604                         world.step(Time.getTicksFraction(), 10, 10);\r
605                 }\r
606                 gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
607                 gl.glMatrixMode(GL10.GL_MODELVIEW);\r
608         gl.glLoadIdentity();\r
609                 for(int i = 0; i < layerCount; i++) {\r
610                         layer[i].onDraw(gl);\r
611                 }\r
612                 onPostDraw(gl);\r
613         }\r
614         \r
615         protected boolean pausePhysics = false;\r
616         \r
617         public void pausePhysics() {\r
618                 pausePhysics = true;\r
619         }\r
620         \r
621         public void resumePhysics() {\r
622                 pausePhysics = false;\r
623         }\r
624         \r
625         protected class SceneContactListener implements ContactListener {\r
626 \r
627                 public void beginContact(Contact contact) {\r
628                         // TODO Auto-generated method stub\r
629                         \r
630                 }\r
631 \r
632                 public void endContact(Contact contact) {\r
633                         // TODO Auto-generated method stub\r
634                         \r
635                 }\r
636                 \r
637         }\r
638         \r
639         public void useContactListener() {\r
640                 if(contactListener == null) {\r
641                         contactListener = new SceneContactListener();\r
642                 }\r
643                 useContactListener = true;\r
644         }\r
645         \r
646         public void stopContactListener() {\r
647                 useContactListener = false;\r
648         }\r
649         \r
650         public void setContactListener(ContactListener contactListener) {\r
651                 this.contactListener = contactListener;\r
652         }\r
653         \r
654         \r
655         \r
656 }\r