Skip to content

Commit

Permalink
Cherrypicked previous change from GLES2-Scripting into GLES2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Gramlich committed Mar 21, 2012
1 parent 88299af commit 6a7269e
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 17 deletions.
1 change: 1 addition & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<activity android:name=".BitmapFontExample" android:configChanges="orientation"/>
<activity android:name=".BoundCameraExample" android:configChanges="orientation"/>
<activity android:name=".CanvasTextureCompositingExample" android:configChanges="orientation"/>
<activity android:name=".CardinalSplineMoveModifierExample" android:configChanges="orientation"/>
<activity android:name=".ChangeableTextExample" android:configChanges="orientation"/>
<activity android:name=".CollisionDetectionExample" android:configChanges="orientation"/>
<activity android:name=".ColorKeyTextureSourceDecoratorExample" android:configChanges="orientation"/>
Expand Down
4 changes: 4 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

<string name="btn_get_involved_caption">Open Source - Get involved...</string>

<string name="dialog_device_not_supported_title">Unsupported Device detected!</string>
<string name="dialog_device_not_supported_message">Your device isn\'t supported by <b>AndEngine</b>!\n\nPlease send your device information to nicolasgramlich@gmail.com so that we can hopefully add support in the next release!</string>

<string name="dialog_first_app_launch_title">AndEngine - Examples</string>
<string name="dialog_first_app_launch_message">Welcome to <b>AndEngine</b> the:\n - Free\n - Open Source\n - 2D OpenGL \n - Game-Engine\nfor the Google Android platform.\n\nThese <b>examples</b> are meant for <b>developers</b> to showcase what can be done with <b>AndEngine</b>.\n\nIt\'s Open Source - Get involved!\n\nBest Regards,\nNicolas Gramlich</string>

Expand Down Expand Up @@ -50,6 +53,7 @@
<string name="example_bitmapfont">Using a BitmapFont</string>
<string name="example_boundcamera">Using a BoundCamera</string>
<string name="example_canvastexturecompositing">Compositing Textures (Canvas)</string>
<string name="example_cardinalsplinemovemodifier">Cardinal Spline</string>
<string name="example_changeabletext">Changeable Text</string>
<string name="example_collisiondetection">Collision Detection</string>
<string name="example_colorkeytexturesourcedecorator">Using a ColorKeyTextureSourceDecorator</string>
Expand Down
150 changes: 150 additions & 0 deletions src/org/andengine/examples/CardinalSplineMoveModifierExample.java
Original file line number Diff line number Diff line change
@@ -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
// ===========================================================
}
2 changes: 2 additions & 0 deletions src/org/andengine/examples/launcher/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
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 @@ -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,
Expand Down
45 changes: 29 additions & 16 deletions src/org/andengine/examples/launcher/ExampleLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Arrays;

import org.andengine.AndEngine;
import org.andengine.examples.R;
import org.andengine.util.debug.Debug;

Expand All @@ -21,7 +22,7 @@
import android.widget.Toast;

/**
* (c) 2010 Nicolas Gramlich
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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();
}

// ===========================================================
Expand All @@ -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)
Expand All @@ -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())
Expand All @@ -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();
Expand Down

0 comments on commit 6a7269e

Please sign in to comment.