Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<activity android:name=".AutoParallaxBackgroundExample" android:configChanges="orientation"/>
<activity android:name=".BitmapFontExample" android:configChanges="orientation"/>
<activity android:name=".BoundCameraExample" android:configChanges="orientation"/>
<activity android:name=".ButtonSpriteExample" android:configChanges="orientation"/>
<activity android:name=".CanvasTextureCompositingExample" android:configChanges="orientation"/>
<activity android:name=".ChangeableTextExample" android:configChanges="orientation"/>
<activity android:name=".CollisionDetectionExample" android:configChanges="orientation"/>
Expand Down Expand Up @@ -74,6 +75,7 @@
<activity android:name=".PhysicsRevoluteJointExample" android:configChanges="orientation"/>
<activity android:name=".PhysicsMouseJointExample" android:configChanges="orientation"/>
<activity android:name=".PinchZoomExample" android:configChanges="orientation"/>
<activity android:name=".PolygonExample" android:configChanges="orientation"/>
<activity android:name=".PVRCCZTextureExample" android:configChanges="orientation"/>
<activity android:name=".PVRGZTextureExample" android:configChanges="orientation"/>
<activity android:name=".PVRTextureExample" android:configChanges="orientation"/>
Expand Down
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<string name="example_autoparallaxbackground">Using an AutoParallaxBackground</string>
<string name="example_bitmapfont">Using a BitmapFont</string>
<string name="example_boundcamera">Using a BoundCamera</string>
<string name="example_buttonsprite">Simple two states button</string>
<string name="example_canvastexturecompositing">Compositing Textures (Canvas)</string>
<string name="example_changeabletext">Changeable Text</string>
<string name="example_collisiondetection">Collision Detection</string>
Expand Down Expand Up @@ -87,6 +88,7 @@
<string name="example_physicsjump">Combining Physics and Touch</string>
<string name="example_physicsremove">Removing a Physics Object</string>
<string name="example_pinchzoom">Using PinchZoom</string>
<string name="example_polygon">Drawing Polygons</string>
<string name="example_pvrccztexture">PVRCCZ Texture</string>
<string name="example_pvrgztexture">PVRGZ Texture</string>
<string name="example_pvrtexture">PVR Texture</string>
Expand Down
2 changes: 1 addition & 1 deletion src/org/andengine/examples/PhysicsExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
127 changes: 127 additions & 0 deletions src/org/andengine/examples/PolygonExample.java
Original file line number Diff line number Diff line change
@@ -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
// ===========================================================
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/org/andengine/examples/launcher/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/org/andengine/examples/launcher/ExampleGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down