刚看了下CardinalSplineMoveModifierExample,将里面大致看了下,写了点注释,代码主题如下:
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 = 400;
private static final float DURATION = 4;
private static final float SIZE = 25;
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++) {
final float tension = MathUtils.random(-0.5f, 0.5f);
this.addRectangleWithTension(scene, tension,
MathUtils.random(0, DURATION * 2f));
}
return scene;
}
private void addRectangleWithTension(final Scene pScene,
final float pTension, float pDelay) {
// 声明矩形
final Rectangle rectangle = new Rectangle(-SIZE, -SIZE, SIZE, SIZE,
this.getVertexBufferObjectManager());
rectangle.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE);
if (pTension < 0) {
// 此处原本为rectangle.setColor(1 - pTension, 0, 0, 0.5f);
// 修改成这样只是为了多几个颜色,好玩而已
rectangle.setColor(1 - pTension, pDelay, pDelay, 0.5f);
} else {
rectangle.setColor(pTension, pDelay, pDelay, 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表示的是,左边那半部分
catmullRomMoveModifierConfig1.setControlPoint(i,
CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS[i]
- SIZE / 2,
CardinalSplineMoveModifierExample.CONTROLPOINT_YS[i] - SIZE
/ 2);
// 设置控制点,catmullRomMoveModifierConfig2表示右半部分
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,
EaseLinear
.getInstance()),
// 旋转修饰器
new RotationModifier(
CardinalSplineMoveModifierExample.DURATION,
-45, -315)),
// 集合修饰器
new ParallelEntityModifier(
// 基数样条修饰器
new CardinalSplineMoveModifier(
CardinalSplineMoveModifierExample.DURATION,
catmullRomMoveModifierConfig2,
EaseLinear
.getInstance()),
// 旋转修饰器
new RotationModifier(
CardinalSplineMoveModifierExample.DURATION,
45, 315))))));
pScene.attachChild(rectangle);
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
早上起来,争取能防着写一个W形状出来!