public class MapMgr {
public static MapMgr mapMgr = null;
private int map_num = 28;
private int b_x = 0;
private int b_y = 0;
private int ;
private int ;
private Bitmap bmpView = null;
//create by danielinbiti,前提,你图片确实比屏幕大,如果不比屏幕大,下面注释行修改一下即可。
public static void init(int width,int height){
if(mapMgr==null){
mapMgr = new MapMgr(width,height);
}
}
public static MapMgr getInstance(){
return mapMgr;
}
public MapMgr(int width,int height){
this.width = width;
this.height = height;
Bitmap bmp = PicMgr.getInstance().getBackGroundBitmap();
b_x = (bmp.getWidth()-width)/2;//保证图片比屏幕大
b_y = (bmp.getHeight()-height)/2;
bmpView = Bitmap.createBitmap(bmp, b_x, b_y, width, height);
}
public void logic(){
}
public void mapDown(){
Bitmap bmp = PicMgr.getInstance().getBackGroundBitmap();
if(b_y+heightbmp.getHeight()){
b_y = bmp.getHeight() - height;
}
}
bmpView = Bitmap.createBitmap(bmp, b_x, b_y, width, height);
}
public void mapUp(){
Bitmap bmp = PicMgr.getInstance().getBackGroundBitmap();
if(b_y>0){
b_y = b_y - bmp.getHeight()/map_num;
if(b_y<0){
b_y = 0;
}
}
bmpView = Bitmap.createBitmap(bmp, b_x, b_y, width, height);
}
public void mapLeft(){
Bitmap bmp = PicMgr.getInstance().getBackGroundBitmap();
if(b_x>0){
b_x = b_x - bmp.getWidth()/map_num;
if(b_x<0){
b_x = 0;
}
}
bmpView = Bitmap.createBitmap(bmp, b_x, b_y, width, height);
}
public void mapRight(){
Bitmap bmp = PicMgr.getInstance().getBackGroundBitmap();
if(b_x+widthbmp.getWidth()){
b_x = bmp.getHeight() - width;
}
}
bmpView = Bitmap.createBitmap(bmp, b_x, b_y, width, height);
}
public void draw(Canvas canvas){
Paint paint = new Paint();
if(bmpView!=null){
canvas.drawBitmap(bmpView,0, 0, paint);
}
}
}
调用
public void onKeyDownDeal(int keyCode){ if(keyCode==KeyEvent.KEYCODE_DPAD_UP){ MapMgr.getInstance().mapUp(); }else if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN){ MapMgr.getInstance().mapDown(); }else if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT){ MapMgr.getInstance().mapLeft(); }else if(keyCode==KeyEvent.KEYCODE_DPAD_RIGHT){ MapMgr.getInstance().mapRight(); } }
然后使用线程调用draw刷新即可。
对于触摸移动只是坐标计算方式不同,其它都类似。另外扩充到GIS等,可以根据小图片粘贴实现局部加载内容。
凡尔赛法环免广告版 最新版v1.69.1
下载天煞异种 安卓版v1.0.21
下载十三月 (Undecember)最新官方中文版v3.26.0200
下载我不是废柴无限99999钻999999金币游戏 不减反增版v1.2.16
下载我的女友是声优免广告 安卓版v1
我的女友是声优免广告是一款非常好玩的模拟经营类手游,玩家在游
石器帝国去广告版 v8
石器帝国免广告版是游戏的破解版本,在该版本中为玩家去除了广告
校园恋爱模拟器真人版去广告版 v0.0.7
校园恋爱模拟器真人版免广告版是游戏的破解版本,在该版本中为玩
教练我要开球馆内置菜单修改器 安卓版v1.5.4
教练我要开球馆内购版是一款模拟经营类游戏,玩家们将在游戏中创
我的游轮无限砖石 安卓版v1.7.0
我的游轮无限金币钻石版是一款模拟经营类游戏,你将成为一艘游轮