diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a3dcd43..263fc64 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -37,6 +37,7 @@ + diff --git a/res/values/strings.xml b/res/values/strings.xml index 7f67937..e912cd8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4,6 +4,9 @@ Open Source - Get involved... + Unsupported Device detected! + Your device isn\'t supported by AndEngine!\n\nPlease send your device information to nicolasgramlich@gmail.com so that we can hopefully add support in the next release! + AndEngine - Examples Welcome to AndEngine the:\n - Free\n - Open Source\n - 2D OpenGL \n - Game-Engine\nfor the Google Android platform.\n\nThese examples are meant for developers to showcase what can be done with AndEngine.\n\nIt\'s Open Source - Get involved!\n\nBest Regards,\nNicolas Gramlich @@ -50,6 +53,7 @@ Using a BitmapFont Using a BoundCamera Compositing Textures (Canvas) + Cardinal Spline Changeable Text Collision Detection Using a ColorKeyTextureSourceDecorator diff --git a/src/org/andengine/examples/CardinalSplineMoveModifierExample.java b/src/org/andengine/examples/CardinalSplineMoveModifierExample.java new file mode 100644 index 0000000..db15ae8 --- /dev/null +++ b/src/org/andengine/examples/CardinalSplineMoveModifierExample.java @@ -0,0 +1,150 @@ +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.modifier.CardinalSplineMoveModifier; +import org.andengine.entity.modifier.CardinalSplineMoveModifier.CardinalSplineMoveModifierConfig; +import org.andengine.entity.modifier.DelayModifier; +import org.andengine.entity.modifier.LoopEntityModifier; +import org.andengine.entity.modifier.ParallelEntityModifier; +import org.andengine.entity.modifier.RotationModifier; +import org.andengine.entity.modifier.SequenceEntityModifier; +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.ui.activity.SimpleBaseGameActivity; +import org.andengine.util.math.MathUtils; + +import android.opengl.GLES20; + +/** + * (c) 2010 Nicolas Gramlich + * (c) 2011 Zynga + * + * @author Nicolas Gramlich + * @since 11:54:51 - 03.04.2010 + */ +public class CardinalSplineMoveModifierExample extends SimpleBaseGameActivity { + // =========================================================== + // Constants + // =========================================================== + + private static final int CAMERA_WIDTH = 720; + private static final int CAMERA_HEIGHT = 480; + + private static final int COUNT = 500; + private static final float DURATION = 4; + private static final float SIZE = 20; + + private static final float[] CONTROLPOINT_1_XS = { + 2 * (CAMERA_WIDTH / 4), + 1 * (CAMERA_WIDTH / 4), + 1.5f * (CAMERA_WIDTH / 4), + 2 * (CAMERA_WIDTH / 4) + }; + + private static final float[] CONTROLPOINT_2_XS = { + 2 * (CAMERA_WIDTH / 4), + 3 * (CAMERA_WIDTH / 4), + 2.5f * (CAMERA_WIDTH / 4), + 2 * (CAMERA_WIDTH / 4) + }; + + private static final float[] CONTROLPOINT_YS = { + 3.5f * (CAMERA_HEIGHT / 4), + 2 * (CAMERA_HEIGHT / 4), + 1 * (CAMERA_HEIGHT / 4), + 1.5f * (CAMERA_HEIGHT / 4), + }; + + // =========================================================== + // 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, 0, 0)); + + for(int i = 0; i < COUNT; i++) { + this.addRectangleWithTension(scene, MathUtils.random(-1f, 1f), MathUtils.random(0, DURATION * 2f)); + } + + return scene; + } + + private void addRectangleWithTension(final Scene pScene, final float pTension, float pDelay) { + final Rectangle rectangle = new Rectangle(0, 0, SIZE, SIZE, this.getVertexBufferObjectManager()); + rectangle.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE); + if(pTension < 0) { + rectangle.setColor(1 - pTension, 0, 0, 0.5f); + } else { + rectangle.setColor(pTension, 0, 0, 0.5f); + } + + final CardinalSplineMoveModifierConfig catmullRomMoveModifierConfig1 = new CardinalSplineMoveModifierConfig(CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS.length, pTension); + final CardinalSplineMoveModifierConfig catmullRomMoveModifierConfig2 = new CardinalSplineMoveModifierConfig(CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS.length, pTension); + + for(int i = 0; i < CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS.length; i++) { + catmullRomMoveModifierConfig1.setControlPoint(i, CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS[i] - SIZE / 2, CardinalSplineMoveModifierExample.CONTROLPOINT_YS[i] - SIZE / 2); + catmullRomMoveModifierConfig2.setControlPoint(i, CardinalSplineMoveModifierExample.CONTROLPOINT_2_XS[i] - SIZE / 2, CardinalSplineMoveModifierExample.CONTROLPOINT_YS[i] - SIZE / 2); + } + + rectangle.registerEntityModifier( + new SequenceEntityModifier( + new DelayModifier(pDelay), + new LoopEntityModifier( + new SequenceEntityModifier( + new ParallelEntityModifier( + new CardinalSplineMoveModifier(CardinalSplineMoveModifierExample.DURATION, catmullRomMoveModifierConfig1), + new RotationModifier(CardinalSplineMoveModifierExample.DURATION, 0, 360) + ), + new ParallelEntityModifier( + new CardinalSplineMoveModifier(CardinalSplineMoveModifierExample.DURATION, catmullRomMoveModifierConfig2), + new RotationModifier(CardinalSplineMoveModifierExample.DURATION, 0, 360) + ) + ) + ) + ) + ); + + pScene.attachChild(rectangle); + } + + // =========================================================== + // Methods + // =========================================================== + + // =========================================================== + // Inner and Anonymous Classes + // =========================================================== +} diff --git a/src/org/andengine/examples/launcher/Example.java b/src/org/andengine/examples/launcher/Example.java index 26a4b20..75de4ac 100644 --- a/src/org/andengine/examples/launcher/Example.java +++ b/src/org/andengine/examples/launcher/Example.java @@ -7,6 +7,7 @@ import org.andengine.examples.BitmapFontExample; import org.andengine.examples.BoundCameraExample; import org.andengine.examples.CanvasTextureCompositingExample; +import org.andengine.examples.CardinalSplineMoveModifierExample; import org.andengine.examples.CollisionDetectionExample; import org.andengine.examples.ColorKeyTextureSourceDecoratorExample; import org.andengine.examples.CoordinateConversionExample; @@ -105,6 +106,7 @@ enum Example { AUTOPARALLAXBACKGROUND(AutoParallaxBackgroundExample.class, R.string.example_autoparallaxbackground), BITMAPFONT(BitmapFontExample.class, R.string.example_bitmapfont), BOUNDCAMERA(BoundCameraExample.class, R.string.example_boundcamera), + CARDINALSPLINEMOVEMODIFIER(CardinalSplineMoveModifierExample.class, R.string.example_cardinalsplinemovemodifier), CANVASTEXTURECOMPOSITING(CanvasTextureCompositingExample.class, R.string.example_canvastexturecompositing), CHANGEABLETEXT(TextExample.class, R.string.example_changeabletext), COLLISIONDETECTION(CollisionDetectionExample.class, R.string.example_collisiondetection), diff --git a/src/org/andengine/examples/launcher/ExampleGroup.java b/src/org/andengine/examples/launcher/ExampleGroup.java index 2e3b0b1..8d3b94e 100644 --- a/src/org/andengine/examples/launcher/ExampleGroup.java +++ b/src/org/andengine/examples/launcher/ExampleGroup.java @@ -18,7 +18,7 @@ public enum ExampleGroup { SIMPLE(R.string.examplegroup_simple, Example.LINE, Example.RECTANGLE, Example.SPRITE, Example.SPRITEREMOVE, Example.SPRITEBATCH), MODIFIER_AND_ANIMATION(R.string.examplegroup_modifier_and_animation, - Example.MOVINGBALL, Example.ENTITYMODIFIER, Example.ENTITYMODIFIERIRREGULAR, Example.PATHMODIFIER, Example.ANIMATEDSPRITES, Example.EASEFUNCTION, Example.ROTATION3D ), + Example.MOVINGBALL, Example.ENTITYMODIFIER, Example.ENTITYMODIFIERIRREGULAR, Example.CARDINALSPLINEMOVEMODIFIER, Example.PATHMODIFIER, Example.ANIMATEDSPRITES, Example.EASEFUNCTION, Example.ROTATION3D ), TOUCH(R.string.examplegroup_touch, Example.TOUCHDRAG, Example.MULTITOUCH, Example.ANALOGONSCREENCONTROL, Example.DIGITALONSCREENCONTROL, Example.ANALOGONSCREENCONTROLS, Example.COORDINATECONVERSION, Example.PINCHZOOM), PARTICLESYSTEM(R.string.examplegroup_particlesystems, diff --git a/src/org/andengine/examples/launcher/ExampleLauncher.java b/src/org/andengine/examples/launcher/ExampleLauncher.java index 9694966..66744c3 100644 --- a/src/org/andengine/examples/launcher/ExampleLauncher.java +++ b/src/org/andengine/examples/launcher/ExampleLauncher.java @@ -2,6 +2,7 @@ import java.util.Arrays; +import org.andengine.AndEngine; import org.andengine.examples.R; import org.andengine.util.debug.Debug; @@ -21,7 +22,7 @@ import android.widget.Toast; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich @@ -35,8 +36,9 @@ public class ExampleLauncher extends ExpandableListActivity { private static final String PREF_LAST_APP_LAUNCH_VERSIONCODE_ID = "last.app.launch.versioncode"; private static final int DIALOG_FIRST_APP_LAUNCH = 0; - private static final int DIALOG_NEW_IN_THIS_VERSION = DIALOG_FIRST_APP_LAUNCH + 1; - private static final int DIALOG_BENCHMARKS_SUBMIT_PLEASE = DIALOG_NEW_IN_THIS_VERSION + 1; + private static final int DIALOG_NEW_IN_THIS_VERSION = ExampleLauncher.DIALOG_FIRST_APP_LAUNCH + 1; + private static final int DIALOG_BENCHMARKS_SUBMIT_PLEASE = ExampleLauncher.DIALOG_NEW_IN_THIS_VERSION + 1; + private static final int DIALOG_DEVICE_NOT_SUPPORTED = ExampleLauncher.DIALOG_BENCHMARKS_SUBMIT_PLEASE + 1; // =========================================================== // Fields @@ -56,6 +58,10 @@ public class ExampleLauncher extends ExpandableListActivity { public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if(!AndEngine.isDeviceSupported()) { + this.showDialog(ExampleLauncher.DIALOG_DEVICE_NOT_SUPPORTED); + } + this.setContentView(R.layout.list_examples); this.mExpandableExampleLauncherListAdapter = new ExpandableExampleLauncherListAdapter(this); @@ -72,17 +78,17 @@ public void onClick(final View pView) { final SharedPreferences prefs = this.getPreferences(Context.MODE_PRIVATE); this.mVersionCodeCurrent = this.getVersionCode(); - this.mVersionCodeLastLaunch = prefs.getInt(PREF_LAST_APP_LAUNCH_VERSIONCODE_ID, -1); + this.mVersionCodeLastLaunch = prefs.getInt(ExampleLauncher.PREF_LAST_APP_LAUNCH_VERSIONCODE_ID, -1); if(this.isFirstTime("first.app.launch")) { - this.showDialog(DIALOG_FIRST_APP_LAUNCH); - } else if(this.mVersionCodeLastLaunch != -1 && this.mVersionCodeLastLaunch < this.mVersionCodeCurrent){ - this.showDialog(DIALOG_NEW_IN_THIS_VERSION); - } else if(isFirstTime("please.submit.benchmarks")){ - this.showDialog(DIALOG_BENCHMARKS_SUBMIT_PLEASE); + this.showDialog(ExampleLauncher.DIALOG_FIRST_APP_LAUNCH); + } else if((this.mVersionCodeLastLaunch != -1) && (this.mVersionCodeLastLaunch < this.mVersionCodeCurrent)){ + this.showDialog(ExampleLauncher.DIALOG_NEW_IN_THIS_VERSION); + } else if(this.isFirstTime("please.submit.benchmarks")){ + this.showDialog(ExampleLauncher.DIALOG_BENCHMARKS_SUBMIT_PLEASE); } - prefs.edit().putInt(PREF_LAST_APP_LAUNCH_VERSIONCODE_ID, this.mVersionCodeCurrent).commit(); + prefs.edit().putInt(ExampleLauncher.PREF_LAST_APP_LAUNCH_VERSIONCODE_ID, this.mVersionCodeCurrent).commit(); } // =========================================================== @@ -96,6 +102,13 @@ public void onClick(final View pView) { @Override protected Dialog onCreateDialog(final int pId) { switch(pId) { + case DIALOG_DEVICE_NOT_SUPPORTED: + return new AlertDialog.Builder(this) + .setTitle(R.string.dialog_device_not_supported_title) + .setMessage(R.string.dialog_device_not_supported_message) + .setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton(android.R.string.ok, null) + .create(); case DIALOG_FIRST_APP_LAUNCH: return new AlertDialog.Builder(this) .setTitle(R.string.dialog_first_app_launch_title) @@ -113,21 +126,21 @@ protected Dialog onCreateDialog(final int pId) { case DIALOG_NEW_IN_THIS_VERSION: final int[] versionCodes = this.getResources().getIntArray(R.array.new_in_version_versioncode); final int versionDescriptionsStartIndex = Math.max(0, Arrays.binarySearch(versionCodes, this.mVersionCodeLastLaunch) + 1); - + final String[] versionDescriptions = this.getResources().getStringArray(R.array.new_in_version_changes); - + final StringBuilder sb = new StringBuilder(); for(int i = versionDescriptions.length - 1; i >= versionDescriptionsStartIndex; i--) { sb.append("--------------------------\n"); sb.append(">>> Version: " + versionCodes[i] + "\n"); sb.append("--------------------------\n"); sb.append(versionDescriptions[i]); - + if(i > versionDescriptionsStartIndex){ sb.append("\n\n"); } } - + return new AlertDialog.Builder(this) .setTitle(R.string.dialog_new_in_this_version_title) .setMessage(sb.toString()) @@ -138,9 +151,9 @@ protected Dialog onCreateDialog(final int pId) { return super.onCreateDialog(pId); } } - + @Override - public void onGroupExpand(int pGroupPosition) { + public void onGroupExpand(final int pGroupPosition) { switch(this.mExpandableExampleLauncherListAdapter.getGroup(pGroupPosition)){ case BENCHMARK: Toast.makeText(this, "When running a benchmark, a dialog with the results will appear after some seconds.", Toast.LENGTH_SHORT).show();