pathModifier



public class PathModifierExample extends SimpleBaseGameActivity {
 // ===========================================================
 // Constants
 // ===========================================================

 private static final int CAMERA_WIDTH = 720;
 private static final int CAMERA_HEIGHT = 480;

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

 private RepeatingSpriteBackground mGrassBackground;

 private BitmapTextureAtlas mBitmapTextureAtlas;
 private TiledTextureRegion mPlayerTextureRegion;

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

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

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

 @Override
 public EngineOptions onCreateEngineOptions() {
  Toast.makeText(this, "You move my sprite right round, right round...",
    Toast.LENGTH_LONG).show();

  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() {
  BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
  // 实例化可重复的精灵背景
  this.mGrassBackground = new RepeatingSpriteBackground(CAMERA_WIDTH,
    CAMERA_HEIGHT, this.getTextureManager(),
    AssetBitmapTextureAtlasSource.create(this.getAssets(),
      "gfx/background_grass.png"),
    this.getVertexBufferObjectManager());
  // 创建纹理集
  this.mBitmapTextureAtlas = new BitmapTextureAtlas(
    this.getTextureManager(), 128, 128);
  // 创建纹理区域
  this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory
    .createTiledFromAsset(this.mBitmapTextureAtlas, this,
      "player.png", 0, 0, 3, 4);
  this.mBitmapTextureAtlas.load();
 }

 @Override
 public Scene onCreateScene() {
  this.mEngine.registerUpdateHandler(new FPSLogger());

  final Scene scene = new Scene();
  scene.setBackground(this.mGrassBackground);

  /* Create the face and add it to the scene. */
  final AnimatedSprite player = new AnimatedSprite(10, 10, 48, 64,
    this.mPlayerTextureRegion, this.getVertexBufferObjectManager());
  // 指定其行走的路线
  final Path path = new Path(5).to(10, 10).to(10, CAMERA_HEIGHT - 74)
    .to(CAMERA_WIDTH - 58, CAMERA_HEIGHT - 74)
    .to(CAMERA_WIDTH - 58, 10).to(10, 10);

  /* Add the proper animation when a waypoint of the path is passed. */
  player.registerEntityModifier(
  // 循环实体修饰集合
  new LoopEntityModifier(
  // 构造路线修饰实体
    new PathModifier(30, path, null, new IPathModifierListener() {
     @Override
     public void onPathStarted(final PathModifier pPathModifier,
       final IEntity pEntity) {
      Debug.d("onPathStarted");
     }

     @Override
     public void onPathWaypointStarted(
       final PathModifier pPathModifier,
       final IEntity pEntity, final int pWaypointIndex) {
      Debug.d("onPathWaypointStarted:  " + pWaypointIndex);
      switch (pWaypointIndex) {
      // 人物向下走的时候,使用第6到第8张图
      case 0:
       player.animate(new long[] { 200, 200, 200 }, 6, 8,
         true);
       break;
      // 人物像向走的时候,使用第3到第5张图
      case 1:
       player.animate(new long[] { 200, 200, 200 }, 3, 5,
         true);
       break;
      // 人物向上走的时候,使用第0到2张图
      case 2:
       player.animate(new long[] { 200, 200, 200 }, 0, 2,
         true);
       break;
      // 人物向左走的号死后,使用第9到11张图
      case 3:
       player.animate(new long[] { 200, 200, 200 }, 9, 11,
         true);
       break;
      }
     }

     @Override
     public void onPathWaypointFinished(
       final PathModifier pPathModifier,
       final IEntity pEntity, final int pWaypointIndex) {
      Debug.d("onPathWaypointFinished: " + pWaypointIndex);
     }

     @Override
     public void onPathFinished(
       final PathModifier pPathModifier,
       final IEntity pEntity) {
      Debug.d("onPathFinished");
     }
    }, EaseSineInOut.getInstance())));
  scene.attachChild(player);

  return scene;
 }

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值