-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherrypicked previous change from GLES2-Scripting into GLES2.
- Loading branch information
Nicolas Gramlich
committed
Mar 21, 2012
1 parent
88299af
commit 6a7269e
Showing
6 changed files
with
187 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
src/org/andengine/examples/CardinalSplineMoveModifierExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
// =========================================================== | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters