[AndEngine学习教程] 第3节 使用Modifier修改动画

转自:http://blog.csdn.net/cen616899547/article/details/8128334

1.AndEngine的动画修改器(modifier)有很多种,常用的有一下几种:

1.AlphaModifier:透明度修改器,有以下几种构造:

  1. public AlphaModifier(finalfloat pDuration, finalfloat pFromAlpha, finalfloat pToAlpha) {
  2. this(pDuration, pFromAlpha, pToAlpha,null, EaseLinear.getInstance());
  3. }
  4. public AlphaModifier(finalfloat pDuration, finalfloat pFromAlpha, finalfloat pToAlpha, final IEaseFunction pEaseFunction) {
  5. this(pDuration, pFromAlpha, pToAlpha,null, pEaseFunction);
  6. }
  7. public AlphaModifier(finalfloat pDuration, finalfloat pFromAlpha, finalfloat pToAlpha, final IEntityModifierListener pEntityModifierListener) {
  8. super(pDuration, pFromAlpha, pToAlpha, pEntityModifierListener, EaseLinear.getInstance());
  9. }
  10. public AlphaModifier(finalfloat pDuration, finalfloat pFromAlpha, finalfloat pToAlpha, final IEntityModifierListener pEntityModifierListener,final IEaseFunction pEaseFunction) {
  11. super(pDuration, pFromAlpha, pToAlpha, pEntityModifierListener, pEaseFunction);
  12. }
  13. protected AlphaModifier(final AlphaModifier pAlphaModifier) {
  14. super(pAlphaModifier);
  15. }
public AlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha) {
		this(pDuration, pFromAlpha, pToAlpha, null, EaseLinear.getInstance());
	}

	public AlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha, final IEaseFunction pEaseFunction) {
		this(pDuration, pFromAlpha, pToAlpha, null, pEaseFunction);
	}

	public AlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha, final IEntityModifierListener pEntityModifierListener) {
		super(pDuration, pFromAlpha, pToAlpha, pEntityModifierListener, EaseLinear.getInstance());
	}

	public AlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) {
		super(pDuration, pFromAlpha, pToAlpha, pEntityModifierListener, pEaseFunction);
	}

	protected AlphaModifier(final AlphaModifier pAlphaModifier) {
		super(pAlphaModifier);
	}

pDuration代表动画修改周期,就是就是完成整个透明度变化所要的时间,单位为秒.
pFromAlpha代表起始透明度
pToAlpha代表目标透明度


2.ScaleModifier,比例修改器.主要是对动画的大小比例进行修改:

  1. public ScaleModifier(finalfloat pDuration, finalfloat pFromScale, finalfloat pToScale) {
  2. this(pDuration, pFromScale, pToScale,null, EaseLinear.getInstance());
  3. }
  4. public ScaleModifier(finalfloat pDuration, finalfloat pFromScale, finalfloat pToScale, final IEaseFunction pEaseFunction) {
  5. this(pDuration, pFromScale, pToScale,null, pEaseFunction);
  6. }
  7. public ScaleModifier(finalfloat pDuration, finalfloat pFromScale, finalfloat pToScale, final IEntityModifierListener pEntityModifierListener) {
  8. this(pDuration, pFromScale, pToScale, pFromScale, pToScale, pEntityModifierListener, EaseLinear.getInstance());
  9. }
  10. public ScaleModifier(finalfloat pDuration, finalfloat pFromScale, finalfloat pToScale, final IEntityModifierListener pEntityModifierListener,final IEaseFunction pEaseFunction) {
  11. this(pDuration, pFromScale, pToScale, pFromScale, pToScale, pEntityModifierListener, pEaseFunction);
  12. }
  13. public ScaleModifier(finalfloat pDuration, finalfloat pFromScaleX, finalfloat pToScaleX, finalfloat pFromScaleY, finalfloat pToScaleY) {
  14. this(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY,null, EaseLinear.getInstance());
  15. }
  16. public ScaleModifier(finalfloat pDuration, finalfloat pFromScaleX, finalfloat pToScaleX, finalfloat pFromScaleY, finalfloat pToScaleY, final IEaseFunction pEaseFunction) {
  17. this(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY,null, pEaseFunction);
  18. }
  19. public ScaleModifier(finalfloat pDuration, finalfloat pFromScaleX, finalfloat pToScaleX, finalfloat pFromScaleY, finalfloat pToScaleY, final IEntityModifierListener pEntityModifierListener) {
  20. super(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, pEntityModifierListener, EaseLinear.getInstance());
  21. }
  22. public ScaleModifier(finalfloat pDuration, finalfloat pFromScaleX, finalfloat pToScaleX, finalfloat pFromScaleY, finalfloat pToScaleY, final IEntityModifierListener pEntityModifierListener,final IEaseFunction pEaseFunction) {
  23. super(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, pEntityModifierListener, pEaseFunction);
  24. }
  25. protected ScaleModifier(final ScaleModifier pScaleModifier) {
  26. super(pScaleModifier);
  27. }
public ScaleModifier(final float pDuration, final float pFromScale, final float pToScale) {
		this(pDuration, pFromScale, pToScale, null, EaseLinear.getInstance());
	}

	public ScaleModifier(final float pDuration, final float pFromScale, final float pToScale, final IEaseFunction pEaseFunction) {
		this(pDuration, pFromScale, pToScale, null, pEaseFunction);
	}

	public ScaleModifier(final float pDuration, final float pFromScale, final float pToScale, final IEntityModifierListener pEntityModifierListener) {
		this(pDuration, pFromScale, pToScale, pFromScale, pToScale, pEntityModifierListener, EaseLinear.getInstance());
	}

	public ScaleModifier(final float pDuration, final float pFromScale, final float pToScale, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) {
		this(pDuration, pFromScale, pToScale, pFromScale, pToScale, pEntityModifierListener, pEaseFunction);
	}

	public ScaleModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY) {
		this(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, null, EaseLinear.getInstance());
	}

	public ScaleModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY, final IEaseFunction pEaseFunction) {
		this(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, null, pEaseFunction);
	}

	public ScaleModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY, final IEntityModifierListener pEntityModifierListener) {
		super(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, pEntityModifierListener, EaseLinear.getInstance());
	}

	public ScaleModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) {
		super(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, pEntityModifierListener, pEaseFunction);
	}

	protected ScaleModifier(final ScaleModifier pScaleModifier) {
		super(pScaleModifier);
	}

pDuration代表动画修改周期,就是就是完成整个变化所要的时间,单位为秒.
pFromScale代表起始透大小比例
pToScale代表目标大小比例


此外,还有DelayModifier,ColorModifier,MoveModifier等等.
另外还有一些组合式的修改器,如SequenceEntityModifierParallelEntityModifier.这类修改器的一个显著特点就是可以同时
对几个样式进行修改而达到想要的效果


2.创建项目
由于我的手机是htc-g12.分辨率为800*480,其他手机的分辨率也可以选择更加合适的分辨率,只要尺寸比例一致就可以了.因为我使用到RatioResolutionPolicy
进行屏幕的绘制.它可以自动缩放到屏幕合适的大小.

  1. private staticfinal String TAG = "Season";
  2. private staticfinal int CAMERA_WIDTH =800;
  3. private staticfinal int CAMERA_HEIGHT =480;
  4. private Camera mCamera;
  5. private Scene mScene;
  6. private RepeatingSpriteBackground background;
  7. private TiledTextureRegion mFaceTextureRegion;
private static final String TAG = "Season";
	private static final int CAMERA_WIDTH = 800;
	private static final int CAMERA_HEIGHT = 480;

	private Camera mCamera;
	private Scene mScene;
	private RepeatingSpriteBackground background;
	private TiledTextureRegion mFaceTextureRegion;

onCreateEngineOptions()处设置 cameraEngineOption选项

  1. @Override
  2. public EngineOptions onCreateEngineOptions() {
  3. // TODO Auto-generated method stub
  4. mCamera = new Camera(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);
  5. EngineOptions mEngineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR,new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
  6. return mEngineOptions;
  7. }
@Override
	public EngineOptions onCreateEngineOptions() {
		// TODO Auto-generated method stub
		
		mCamera = new Camera(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);
		EngineOptions mEngineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
		
		return mEngineOptions;
	}

需要说明的几个参数是有关 EngineOptions的:
回到 EngineOptions的源代码构造函数为:

  1. public EngineOptions(finalboolean pFullscreen, final ScreenOrientation pScreenOrientation,final IResolutionPolicy pResolutionPolicy,final Camera pCamera) {
  2. this.mFullscreen = pFullscreen;
  3. this.mScreenOrientation = pScreenOrientation;
  4. this.mResolutionPolicy = pResolutionPolicy;
  5. this.mCamera = pCamera;
  6. }
public EngineOptions(final boolean pFullscreen, final ScreenOrientation pScreenOrientation, final IResolutionPolicy pResolutionPolicy, final Camera pCamera) {
		this.mFullscreen = pFullscreen;
		this.mScreenOrientation = pScreenOrientation;
		this.mResolutionPolicy = pResolutionPolicy;
		this.mCamera = pCamera;
	}


一目了然:
如果要全屏显示,pFullscreen就应该为true.
pScreenOrientation是一个枚举类型的数据

  1. public enum ScreenOrientation {
  2. // ===========================================================
  3. // Elements
  4. // ===========================================================
  5. /** The app will be fixed in its default Landscape mode. */
  6. LANDSCAPE_FIXED,
  7. /** The app will automatically rotate between the Landscape modes, depending on the orientation of the device. */
  8. LANDSCAPE_SENSOR,
  9. /** The app will be fixed in its default Portrait mode. */
  10. PORTRAIT_FIXED,
  11. /** The app will automatically rotate between the Portrait modes, depending on the orientation of the device. */
  12. PORTRAIT_SENSOR;
  13. }
public enum ScreenOrientation {
	// ===========================================================
	// Elements
	// ===========================================================

	/** The app will be fixed in its default Landscape mode. */
	LANDSCAPE_FIXED,
	/** The app will automatically rotate between the Landscape modes, depending on the orientation of the device. */
	LANDSCAPE_SENSOR,
	/** The app will be fixed in its default Portrait mode. */
	PORTRAIT_FIXED,
	/** The app will automatically rotate between the Portrait modes, depending on the orientation of the device. */
	PORTRAIT_SENSOR;
 }

pResolutionPolicy是屏幕的绘制策略,常用的有这几种: FillResolutionPolicy,FixedResolutionPolicy,RatioResolutionPolicy,RelativeResolutionPolicy,从名字
就可以看出各种策略的大致用途了.
在onCreateResources处,是游戏引擎在创建资源(图片,声音等)进行加载用.

  1. public void onCreateResources(
  2. OnCreateResourcesCallback pOnCreateResourcesCallback)
  3. throws Exception {
  4. // TODO Auto-generated method stub
  5. this.background =new RepeatingSpriteBackground(CAMERA_WIDTH, CAMERA_HEIGHT,
  6. getTextureManager(), AssetBitmapTextureAtlasSource.create(
  7. this.getAssets(),"background.png"),
  8. getVertexBufferObjectManager());
  9. BitmapTextureAtlas mTexture = new BitmapTextureAtlas(getTextureManager(),64,32,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  10. mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mTexture,this, "face_box_tiled.png",0, 0,2,1);
  11. /**
  12. * 参数说明:
  13. * mTexure是在内存中放置贴图资源用的,64,32是图片要求的宽和高,必须是2的n次方大小.如:2,4,8,16,32,64,128,512,1024....
  14. * 并且要比原图的宽高要大
  15. *
  16. * mFaceTextureRegion相当于从mTexure中扣图,因为mTexure是由很多图集组成的,要从中截取一片出来
  17. * 0,0代表截图的top,right坐标(起点坐标),2和1分别代表贴图中一张存在2列1行
  18. *
  19. */
  20. mTexture.load();
  21. pOnCreateResourcesCallback.onCreateResourcesFinished();
  22. }
public void onCreateResources(
			OnCreateResourcesCallback pOnCreateResourcesCallback)
			throws Exception {
		// TODO Auto-generated method stub
		this.background = new RepeatingSpriteBackground(CAMERA_WIDTH, CAMERA_HEIGHT,  
	               getTextureManager(), AssetBitmapTextureAtlasSource.create(  
				    this.getAssets(), "background.png"),  
				    getVertexBufferObjectManager()); 
		
		
		BitmapTextureAtlas mTexture = new BitmapTextureAtlas(getTextureManager(),64,32,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mTexture, this, "face_box_tiled.png", 0, 0,2,1);
		
		/**
		 * 参数说明:
		 * mTexure是在内存中放置贴图资源用的,64,32是图片要求的宽和高,必须是2的n次方大小.如:2,4,8,16,32,64,128,512,1024....
		 * 并且要比原图的宽高要大
		 * 
		 * mFaceTextureRegion相当于从mTexure中扣图,因为mTexure是由很多图集组成的,要从中截取一片出来
		 * 0,0代表截图的top,right坐标(起点坐标),2和1分别代表贴图中一张存在2列1行
		 * 
		 */
		mTexture.load();
		
		pOnCreateResourcesCallback.onCreateResourcesFinished();
	}

onCreateScene是整个游戏的精华之处,所有游戏的控制部分都在这里实现
首先创建场景,布置好背景

  1. mScene = new Scene();
  2. Scene.setBackground(background);
 mScene = new Scene();
mScene.setBackground(background);


接着定位屏幕中心位置,用来放置精灵动画:
  1. final float centerX = (CAMERA_WIDTH - mFaceTextureRegion.getWidth()) /2;//计算贴图的中心坐标
  2. final float centerY = (CAMERA_HEIGHT - mFaceTextureRegion.getHeight()) /2;
     final float centerX = (CAMERA_WIDTH - mFaceTextureRegion.getWidth()) / 2;//计算贴图的中心坐标
     final float centerY = (CAMERA_HEIGHT - mFaceTextureRegion.getHeight()) / 2;

在本例程中,主要创建一个红色的外形和一个贴图动画:

  1. final Rectangle rect = new Rectangle(centerX+100,centerY,32,32,getVertexBufferObjectManager());
  2. rect.setColor(1, 0,0);
  3. final AnimatedSprite face = new AnimatedSprite(centerX - 100, centerY, mFaceTextureRegion, getVertexBufferObjectManager());
  4. face.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
  5. 创建完精灵后,就给精灵添加修改器了,这个地方是比较灵活的,完全根据自己的需要来制作.
  6. final LoopEntityModifier shapeModifier =
  7. new LoopEntityModifier(new IEntityModifierListener(){
  8. @Override
  9. public void onModifierStarted(IModifier<IEntity> pModifier,
  10. IEntity pItem) {
  11. // TODO Auto-generated method stub
  12. Log.d(TAG,"LoopEntityModifier started!");
  13. }
  14. @Override
  15. public void onModifierFinished(
  16. IModifier<IEntity> pModifier, IEntity pItem) {
  17. // TODO Auto-generated method stub
  18. Log.d(TAG,"LoopEntityModifier finished!");
  19. }
  20. },
  21. -1, //无限循环
  22. new ILoopEntityModifierListener(){
  23. @Override
  24. public void onLoopStarted(
  25. LoopModifier<IEntity> pLoopModifier, int pLoop,
  26. int pLoopCount) {
  27. // TODO Auto-generated method stub
  28. Log.d(TAG,"ILoopEntityModifierListener started!");
  29. }
  30. @Override
  31. public void onLoopFinished(
  32. LoopModifier<IEntity> pLoopModifier, int pLoop,
  33. int pLoopCount) {
  34. //Toast.makeText(ShapeModifiers.this, "Loops remaining: " + pLoop, Toast.LENGTH_SHORT).show();
  35. // TODO Auto-generated method stub
  36. Log.d(TAG,"ILoopEntityModifierListener finished!");
  37. }
  38. },
  39. new SequenceEntityModifier(new RotationModifier(1,0, 90),
  40. new AlphaModifier(5,1, 0),
  41. new AlphaModifier(1,0, 1),
  42. new ScaleModifier(2,1, 0.5f),
  43. new DelayModifier(0.5f),
  44. new ParallelEntityModifier(
  45. new ScaleModifier(3,0.5f, 5),
  46. new RotationByModifier(3,90)
  47. ),
  48. new ParallelEntityModifier(
  49. new ScaleModifier(3,5, 1),
  50. new RotationModifier(3,180, 0)){
  51. }));
final Rectangle rect = new Rectangle(centerX+100,centerY,32,32,getVertexBufferObjectManager());
		rect.setColor(1, 0, 0);
		
		final AnimatedSprite face = new AnimatedSprite(centerX - 100, centerY, mFaceTextureRegion, getVertexBufferObjectManager());
		face.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    创建完精灵后,就给精灵添加修改器了,这个地方是比较灵活的,完全根据自己的需要来制作.
    
          final LoopEntityModifier shapeModifier = 
				new LoopEntityModifier(new IEntityModifierListener(){

					@Override
					public void onModifierStarted(IModifier<IEntity> pModifier,
							IEntity pItem) {
						// TODO Auto-generated method stub
						Log.d(TAG,"LoopEntityModifier started!");
					}

					@Override
					public void onModifierFinished(
							IModifier<IEntity> pModifier, IEntity pItem) {
						// TODO Auto-generated method stub
						Log.d(TAG,"LoopEntityModifier finished!");
					}

					
				},
				-1, //无限循环
				new ILoopEntityModifierListener(){

					@Override
					public void onLoopStarted(
							LoopModifier<IEntity> pLoopModifier, int pLoop,
							int pLoopCount) {
						// TODO Auto-generated method stub
						Log.d(TAG,"ILoopEntityModifierListener started!");
					}

					@Override
					public void onLoopFinished(
							LoopModifier<IEntity> pLoopModifier, int pLoop,
							int pLoopCount) {
						//Toast.makeText(ShapeModifiers.this, "Loops remaining: " + pLoop, Toast.LENGTH_SHORT).show();
						// TODO Auto-generated method stub
						Log.d(TAG,"ILoopEntityModifierListener finished!");
					}
				
				}, 
               new SequenceEntityModifier(new RotationModifier(1, 0, 90),
						new AlphaModifier(5, 1, 0),
						new AlphaModifier(1, 0, 1),
						new ScaleModifier(2, 1, 0.5f),
						new DelayModifier(0.5f),
						new ParallelEntityModifier(
								new ScaleModifier(3, 0.5f, 5),
								new RotationByModifier(3, 90)
						),
						new ParallelEntityModifier(
								new ScaleModifier(3, 5, 1),
								new RotationModifier(3, 180, 0)){
					
					
				}));

LoopEntityModifier是一个循环修改器,第三个参数就是循环的次数,-1代表无限重复,从源代码中可以看出各个参数的作用

  1. public class LoopEntityModifier extends LoopModifier<IEntity>implements IEntityModifier {
  2. // ===========================================================
  3. // Constants
  4. // ===========================================================
  5. // ===========================================================
  6. // Fields
  7. // ===========================================================
  8. // ===========================================================
  9. // Constructors
  10. // ===========================================================
  11. public LoopEntityModifier(final IEntityModifier pEntityModifier) {
  12. super(pEntityModifier);
  13. }
  14. public LoopEntityModifier(final IEntityModifier pEntityModifier,final int pLoopCount) {
  15. super(pEntityModifier, pLoopCount);
  16. }
  17. public LoopEntityModifier(final IEntityModifier pEntityModifier,final int pLoopCount,final ILoopEntityModifierListener pLoopModifierListener) {
  18. super(pEntityModifier, pLoopCount, pLoopModifierListener);
  19. }
  20. public LoopEntityModifier(final IEntityModifier pEntityModifier,final int pLoopCount,final IEntityModifierListener pEntityModifierListener) {
  21. super(pEntityModifier, pLoopCount, pEntityModifierListener);
  22. }
  23. public LoopEntityModifier(final IEntityModifierListener pEntityModifierListener,final int pLoopCount,final ILoopEntityModifierListener pLoopModifierListener,final IEntityModifier pEntityModifier) {
  24. super(pEntityModifier, pLoopCount, pLoopModifierListener, pEntityModifierListener);
  25. }
  26. protected LoopEntityModifier(final LoopEntityModifier pLoopEntityModifier)throws DeepCopyNotSupportedException {
  27. super(pLoopEntityModifier);
  28. }
  29. @Override
  30. public LoopEntityModifier deepCopy()throws DeepCopyNotSupportedException {
  31. return new LoopEntityModifier(this);
  32. }
  33. // ===========================================================
  34. // Getter & Setter
  35. // ===========================================================
  36. // ===========================================================
  37. // Methods for/from SuperClass/Interfaces
  38. // ===========================================================
  39. // ===========================================================
  40. // Methods
  41. // ===========================================================
  42. // ===========================================================
  43. // Inner and Anonymous Classes
  44. // ===========================================================
  45. public interface ILoopEntityModifierListenerextends ILoopModifierListener<IEntity> {
  46. // ===========================================================
  47. // Constants
  48. // ===========================================================
  49. // ===========================================================
  50. // Methods
  51. // ===========================================================
  52. }
  53. }
 public class LoopEntityModifier extends LoopModifier<IEntity> implements IEntityModifier {
	// ===========================================================
	// Constants
	// ===========================================================

	// ===========================================================
	// Fields
	// ===========================================================

	// ===========================================================
	// Constructors
	// ===========================================================

	public LoopEntityModifier(final IEntityModifier pEntityModifier) {
		super(pEntityModifier);
	}

	public LoopEntityModifier(final IEntityModifier pEntityModifier, final int pLoopCount) {
		super(pEntityModifier, pLoopCount);
	}

	public LoopEntityModifier(final IEntityModifier pEntityModifier, final int pLoopCount, final ILoopEntityModifierListener pLoopModifierListener) {
		super(pEntityModifier, pLoopCount, pLoopModifierListener);
	}

	public LoopEntityModifier(final IEntityModifier pEntityModifier, final int pLoopCount, final IEntityModifierListener pEntityModifierListener) {
		super(pEntityModifier, pLoopCount, pEntityModifierListener);
	}

	public LoopEntityModifier(final IEntityModifierListener pEntityModifierListener, final int pLoopCount, final ILoopEntityModifierListener pLoopModifierListener, final IEntityModifier pEntityModifier) {
		super(pEntityModifier, pLoopCount, pLoopModifierListener, pEntityModifierListener);
	}

	protected LoopEntityModifier(final LoopEntityModifier pLoopEntityModifier) throws DeepCopyNotSupportedException {
		super(pLoopEntityModifier);
	}

	@Override
	public LoopEntityModifier deepCopy() throws DeepCopyNotSupportedException {
		return new LoopEntityModifier(this);
	}

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================

	// ===========================================================
	// Methods
	// ===========================================================

	// ===========================================================
	// Inner and Anonymous Classes
	// ===========================================================

	public interface ILoopEntityModifierListener extends ILoopModifierListener<IEntity> {
		// ===========================================================
		// Constants
		// ===========================================================

		// ===========================================================
		// Methods
		// ===========================================================
	}
}

最后要做的工作就是将修改器绑定到精灵,将精灵放置到场景中

  1. face.registerEntityModifier(shapeModifier);
  2. rect.registerEntityModifier(shapeModifier.deepCopy());
  3. mScene.attachChild(face);
  4. mScene.attachChild(rect);
  5. pOnCreateSceneCallback.onCreateSceneFinished(mScene);
face.registerEntityModifier(shapeModifier);
		rect.registerEntityModifier(shapeModifier.deepCopy());
		mScene.attachChild(face);
		mScene.attachChild(rect);
		pOnCreateSceneCallback.onCreateSceneFinished(mScene);


3.制作完成的效果如下图所示

效果解释:两个精灵在5秒的时间内慢慢变为透明
在1秒时间内变为完全不透明
尺寸在2秒内变为0.5倍大小
暂停等待0.5秒
在三秒内完成由0.5倍大小到5倍大小渐变,同时旋转90度
在三秒内由5被大小变为一倍大小,同时由180度转回0度




本例子源代码:http://download.csdn.net/detail/cen616899547/4702761

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值