打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
AndEngine镜头追随

AndEngine可以为Camera设置Chase entity来使得镜头随entity移动, 而entity始终在屏幕中间位置。

但有个问题, 如果Player出现在(0,CAMERA_HEIGHT-PLAYER_HEIGHT)的位置,屏幕中3/4的位置可能出现黑屏。


这就需要创建自己的Camera,并更改原有的追随方式(以冒险岛游戏中镜头追随方式为例)

MapleStoryCamera.java

  1. public class MapleStoryCamera extends Camera {  
  2.   
  3.     private Sprite mChaseEntity;  
  4.     private float mBoundsXMax = 16*80;  
  5.     private float mBoundsYMax = 16*50;  
  6.       
  7.     public MapleStoryCamera(float pX, float pY, float pWidth, float pHeight) {  
  8.         super(pX, pY, pWidth, pHeight);  
  9.     }  
  10.       
  11.     public MapleStoryCamera(float pX, float pY, float pWidth, float pHeight, float boundsXMax, float boundsYMax){  
  12.         super(pX, pY, pWidth, pHeight);  
  13.         this.mBoundsXMax = boundsXMax;  
  14.         this.mBoundsYMax = boundsYMax;  
  15.     }  
  16.       
  17.     public void updateChaseEntity() {  
  18.         if(mChaseEntity != null) {  
  19.             final float[] centerCoordinates = mChaseEntity.getSceneCenterCoordinates();  
  20.             float x = centerCoordinates[Constants.VERTEX_INDEX_X];  
  21.             float y = centerCoordinates[Constants.VERTEX_INDEX_Y];  
  22.             if(x < this.getWidth()/2){  
  23.                 x = this.getWidth()/2;  
  24.             }  
  25.             if(x > mBoundsXMax - this.getWidth()/2){  
  26.                 x = mBoundsXMax - this.getWidth()/2;  
  27.             }  
  28.             if(y < this.getHeight()/2){  
  29.                 y = this.getHeight()/2;  
  30.             }  
  31.             if(y > mBoundsYMax - this.getHeight()/2){  
  32.                 y = mBoundsYMax - this.getHeight()/2;  
  33.             }  
  34.             super.setCenter(x, y);  
  35.         }  
  36.     }  
  37.       
  38.     public void setChaseEntity(final Sprite pChaseEntity) {  
  39.         super.setChaseEntity(pChaseEntity);  
  40.         this.mChaseEntity = pChaseEntity;  
  41.     }  
  42. }  
修改后得到理想效果




本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Android两种旋转Bitmap方法
Android高手进阶教程(二十二)之---Android中几种图像特效处理的集锦!! -...
Java Swing读书笔记之二 (Java极富客户端效果开发)
Android中图像变换Matrix的原理、代码验证和应用(二)
android ImageView 按比例动态缩放
Android canvas.drawArc() 画圆弧
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服