diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a3dcd43..080cfa5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -36,6 +36,7 @@ + @@ -74,6 +75,7 @@ + diff --git a/res/values/strings.xml b/res/values/strings.xml index 7f67937..aa357c4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -49,6 +49,7 @@ Using an AutoParallaxBackground Using a BitmapFont Using a BoundCamera + Simple two states button Compositing Textures (Canvas) Changeable Text Collision Detection @@ -87,6 +88,7 @@ Combining Physics and Touch Removing a Physics Object Using PinchZoom + Drawing Polygons PVRCCZ Texture PVRGZ Texture PVR Texture diff --git a/src/org/andengine/examples/PhysicsExample.java b/src/org/andengine/examples/PhysicsExample.java index 5696c3e..a079a1d 100644 --- a/src/org/andengine/examples/PhysicsExample.java +++ b/src/org/andengine/examples/PhysicsExample.java @@ -217,7 +217,7 @@ private static Body createTriangleBody(final PhysicsWorld pPhysicsWorld, final I final float top = -halfHeight; final float bottom = halfHeight; - final float left = -halfHeight; + final float left = -halfWidth; final float centerX = 0; final float right = halfWidth; diff --git a/src/org/andengine/examples/PolygonExample.java b/src/org/andengine/examples/PolygonExample.java new file mode 100644 index 0000000..7810db5 --- /dev/null +++ b/src/org/andengine/examples/PolygonExample.java @@ -0,0 +1,127 @@ +package org.andengine.examples; + +import org.andengine.engine.camera.Camera; +import org.andengine.engine.options.EngineOptions; +import org.andengine.engine.options.EngineOptions.ScreenOrientation; +import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy; +import org.andengine.entity.primitive.Ellipse; +import org.andengine.entity.primitive.PolyLine; +import org.andengine.entity.primitive.Polygon; +import org.andengine.entity.primitive.Rectangle; +import org.andengine.entity.scene.Scene; +import org.andengine.entity.scene.background.Background; +import org.andengine.entity.util.FPSLogger; +import org.andengine.opengl.vbo.VertexBufferObjectManager; +import org.andengine.ui.activity.SimpleBaseGameActivity; +import org.andengine.util.color.Color; + +/** + * + * @author Rodrigo Castro + * @since 23:05:11 - 28.01.2012 + */ +public class PolygonExample extends SimpleBaseGameActivity { + // =========================================================== + // Constants + // =========================================================== + + private static final int CAMERA_WIDTH = 720; + private static final int CAMERA_HEIGHT = 480; + + // =========================================================== + // Fields + // =========================================================== + + // =========================================================== + // Constructors + // =========================================================== + + // =========================================================== + // Getter & Setter + // =========================================================== + + // =========================================================== + // Methods for/from SuperClass/Interfaces + // =========================================================== + + @Override + public EngineOptions onCreateEngineOptions() { + final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); + + return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera); + } + + @Override + public void onCreateResources() { + + } + + @Override + public Scene onCreateScene() { + this.mEngine.registerUpdateHandler(new FPSLogger()); + + final Scene scene = new Scene(); + scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f)); + + // The polygon is closed automatically + final float[] vertexX1 = { 0.0f, 200.0f, 250.0f, 200.0f, 200.0f, 100.0f, 100.0f, 0.0f}; + final float[] vertexY1 = { 0.0f, 0.0f, 50.0f, 100.0f, 200.0f, 150.0f, 50.0f, 50.0f}; + + // This polygon won't be drawn because its vertices are not CCW (Counter ClockWise) + final float[] vertexX2 = { 0.0f, 0.0f, 100.0f, 100.0f, 200.0f, 200.0f, 250.0f, 200.0f}; + final float[] vertexY2 = { 0.0f, 50.0f, 50.0f, 150.0f, 200.0f, 100.0f, 50.0f, 0.0f}; + + final float[] vertexX3 = { 0.0f, 0.0f, 200.0f, 200.0f }; + final float[] vertexY3 = { 0.0f, 100.0f, 100.0f, 0.0f }; + + // Dummy vertices (won't be used) + final float[] vertexX4Dummy = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + final float[] vertexY4Dummy = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + // This polygon can't be triangulated with the current algorithm and will trigger a null pointer exception + final float[] vertexX4 = { 0.0f, 50.0f, 100.0f, 100.0f, 0.0f }; + final float[] vertexY4 = { 0.0f, 150.0f, 0.0f, 100.0f, 100.0f }; + + final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager(); + + final Polygon polygon1 = new Polygon(100, 100, vertexX1, vertexY1, vertexBufferObjectManager); + polygon1.setColor(Color.RED); + + final Polygon polygon2 = new Polygon(400, 500, vertexX2, vertexY2, vertexBufferObjectManager); + polygon2.setColor(Color.GREEN); + + final Polygon polygon3 = new Polygon(20, 350, vertexX3, vertexY3, vertexBufferObjectManager); + polygon3.setColor(Color.PINK); + + //final Polygon polygon4 = new Polygon(20, 350, vertexX4, vertexY4, vertexBufferObjectManager); + //polygon4.setColor(Color.CYAN); + + final PolyLine polyLine = new PolyLine(500, 50, vertexX4Dummy, vertexY4Dummy, vertexBufferObjectManager); + polyLine.setColor(Color.YELLOW); + polyLine.setLineWidth( 7f ); + // Update and use real vertices + polyLine.updateVertices(vertexX4, vertexY4); + + final Ellipse ellipse = new Ellipse(430, 200, 100.0f, 50.0f, vertexBufferObjectManager); + ellipse.setColor(Color.CYAN); + + final Rectangle rectangle = new Rectangle(300, 300, 200, 100, vertexBufferObjectManager); + + scene.attachChild(polygon1); + scene.attachChild(polygon2); + scene.attachChild(polygon3); + //scene.attachChild(polygon4); + scene.attachChild(polyLine); + scene.attachChild(ellipse); + scene.attachChild(rectangle); + + return scene; + } + + // =========================================================== + // Methods + // =========================================================== + + // =========================================================== + // Inner and Anonymous Classes + // =========================================================== +} diff --git a/src/org/andengine/examples/benchmark/AttachDetachBenchmark.java b/src/org/andengine/examples/benchmark/AttachDetachBenchmark.java index 40925e1..841ce37 100644 --- a/src/org/andengine/examples/benchmark/AttachDetachBenchmark.java +++ b/src/org/andengine/examples/benchmark/AttachDetachBenchmark.java @@ -6,7 +6,6 @@ import org.andengine.engine.options.EngineOptions; import org.andengine.engine.options.EngineOptions.ScreenOrientation; import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy; -import org.andengine.entity.IEntity; import org.andengine.entity.scene.Scene; import org.andengine.entity.scene.background.Background; import org.andengine.entity.sprite.Sprite; diff --git a/src/org/andengine/examples/launcher/Example.java b/src/org/andengine/examples/launcher/Example.java index 26a4b20..22e08d0 100644 --- a/src/org/andengine/examples/launcher/Example.java +++ b/src/org/andengine/examples/launcher/Example.java @@ -6,6 +6,7 @@ import org.andengine.examples.AutoParallaxBackgroundExample; import org.andengine.examples.BitmapFontExample; import org.andengine.examples.BoundCameraExample; +import org.andengine.examples.ButtonSpriteExample; import org.andengine.examples.CanvasTextureCompositingExample; import org.andengine.examples.CollisionDetectionExample; import org.andengine.examples.ColorKeyTextureSourceDecoratorExample; @@ -46,6 +47,7 @@ import org.andengine.examples.PhysicsRemoveExample; import org.andengine.examples.PhysicsRevoluteJointExample; import org.andengine.examples.PinchZoomExample; +import org.andengine.examples.PolygonExample; import org.andengine.examples.R; import org.andengine.examples.RadialBlurExample; import org.andengine.examples.RectangleExample; @@ -105,6 +107,7 @@ enum Example { AUTOPARALLAXBACKGROUND(AutoParallaxBackgroundExample.class, R.string.example_autoparallaxbackground), BITMAPFONT(BitmapFontExample.class, R.string.example_bitmapfont), BOUNDCAMERA(BoundCameraExample.class, R.string.example_boundcamera), + BUTTONSPRITE(ButtonSpriteExample.class, R.string.example_buttonsprite), CANVASTEXTURECOMPOSITING(CanvasTextureCompositingExample.class, R.string.example_canvastexturecompositing), CHANGEABLETEXT(TextExample.class, R.string.example_changeabletext), COLLISIONDETECTION(CollisionDetectionExample.class, R.string.example_collisiondetection), @@ -119,6 +122,7 @@ enum Example { HULLALGORITHM(HullAlgorithmExample.class, R.string.example_hullalgorithm), IMAGEFORMATS(ImageFormatsExample.class, R.string.example_imageformats), LEVELLOADER(LevelLoaderExample.class, R.string.example_levelloader), + POLYGON(PolygonExample.class, R.string.example_polygon), LINE(LineExample.class, R.string.example_line), LOADTEXTURE(LoadTextureExample.class, R.string.example_loadtexture), MENU(MenuExample.class, R.string.example_menu), diff --git a/src/org/andengine/examples/launcher/ExampleGroup.java b/src/org/andengine/examples/launcher/ExampleGroup.java index 2e3b0b1..96fc0dc 100644 --- a/src/org/andengine/examples/launcher/ExampleGroup.java +++ b/src/org/andengine/examples/launcher/ExampleGroup.java @@ -16,7 +16,7 @@ public enum ExampleGroup { // =========================================================== SIMPLE(R.string.examplegroup_simple, - Example.LINE, Example.RECTANGLE, Example.SPRITE, Example.SPRITEREMOVE, Example.SPRITEBATCH), + Example.POLYGON, Example.LINE, Example.RECTANGLE, Example.SPRITE, Example.SPRITEREMOVE, Example.SPRITEBATCH, Example.BUTTONSPRITE), MODIFIER_AND_ANIMATION(R.string.examplegroup_modifier_and_animation, Example.MOVINGBALL, Example.ENTITYMODIFIER, Example.ENTITYMODIFIERIRREGULAR, Example.PATHMODIFIER, Example.ANIMATEDSPRITES, Example.EASEFUNCTION, Example.ROTATION3D ), TOUCH(R.string.examplegroup_touch,