主要思路:

通过查资料得知,stage中的默认封装的相机为OrthographicCamera,要操纵该相机,直接把他转化为OrthographicCamera即可使用

但是这会导致一个问题,即原本固定位置的ui也会变动

所以用原stage(gameStage)来装载原ui,用另一个自定义stage(smapStage)来装载游戏地图,内容等

通过操纵smapStage的相机来实现镜头切换

在自定义的SMapStage中,对actor做了定义,如果地图循环,则在地图右末多绘制一个地图宽,在指定位置切镜头,原理可以参照前面的随笔18

actor中也不能再定义x,y,因为他会影响框架的监听,使用原生坐标即可,也是因为此原因,我才改为通过镜头观察地图,而不是原来的移动actor位置等...(这样看我以前的移动actor的写法都是吃力不讨好)

所有代码如下

预览图场景

package com.zhfy.game.screen;

import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.profiling.GLProfiler;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.XmlReader;
import com.badlogic.gdx.utils.XmlReader.Element;
import com.badlogic.gdx.utils.viewport.FillViewport;
import com.badlogic.gdx.utils.viewport.StretchViewport;
import com.zhfy.game.MainGame;
import com.zhfy.game.config.ResConfig;
import com.zhfy.game.framework.GameLayout;
import com.zhfy.game.framework.GameUtil;
import com.zhfy.game.model.framework.CamerDAO;
import com.zhfy.game.model.framework.TextureRegionListDAO;
import com.zhfy.game.screen.stage.SMapStage; /**
* 主游戏场景(游戏主界面), 实现 Screen 接口 或者 继承 ScreenAdapter 类 <br/>
* 这里就展示一张图片代表游戏主界面
*/
public class SMapScreen extends ScreenAdapter { private MainGame game; private SMapStage smapStage;
private Stage gameStage; private TextureRegionListDAO imgLists; private ImageButton button;
//使用场景
private int screenId=81; private int stageId;
private CamerDAO cam; InputProcessorEvent processorEvent;
MapListener mapListener;
InputMultiplexer multiplexer; boolean isTouching;
float touchBaseX;
float touchBaseY;
float touch_X;
float touch_Y;
float moveX;
float moveY;
Label label; Label gameTimeLabel;
//中心点位置
float cx;
float cy;
float javaHeap;
float javaMaxHeap;
boolean ifLoop; //游戏舞台的基本宽高
static float GAMESTAGE_WIDTH;
static float GAMESTAGE_HEIGHT;
//GLProfile gp = new GrayFilter();
GLProfiler gp; //ui
private Element uiR;
private List<Element> ui;
private XmlReader reader ;
private String bgTexture;
private float tempX,tempY,tempW,tempH;
private com.badlogic.gdx.utils.Array<Element> buttonEs;
private Map tempMap; private int i;//function的计数标志,从1开始
// private SMapActor mapActor; public SMapScreen(MainGame mainGame) { this.game=mainGame;
GAMESTAGE_WIDTH=game.getWorldWidth();
GAMESTAGE_HEIGHT=game.getWorldHeight(); //ui
{
reader = ResConfig.reader;
uiR=GameLayout.getXmlERootByScreenId(screenId);
ui=GameUtil.getXmlEByRootE(uiR);
} setStageId(mainGame.getStageId()); //1根据mapid读取地图DAO
//2加载地图图片,生成图片作为背景
/*textureMap=framework.getMapByMapId(mapId);
defMap=framework.getDefMapByMapId(mapId);
mapW=defMap.getWidth();
mapH=defMap.getHeight();
mapSprite = new Sprite(textureMap);*/ //3增加拖动等功能,可以拖动地图
//4替换地图dao的地图素材
//5保存地图 gp =new GLProfiler(Gdx. graphics);
gp.enable(); isTouching=false;
multiplexer = new InputMultiplexer();
//根据screenId初始化资源
//获取对应图片
imgLists=GameUtil.getTextureReigonByScreenId( screenId,mainGame.getAssetManager()); // 使用伸展视口创建舞台
smapStage = new SMapStage(mainGame,new FillViewport(GAMESTAGE_WIDTH, GAMESTAGE_HEIGHT),screenId,imgLists);
// 将输入处理设置到舞台(必须设置, 否则点击按钮没效果)
multiplexer.addProcessor(smapStage);
gameStage = new Stage(new FillViewport(GAMESTAGE_WIDTH, GAMESTAGE_HEIGHT));
multiplexer.addProcessor(gameStage); cam=new CamerDAO(((OrthographicCamera)smapStage.getCamera()),GAMESTAGE_WIDTH,GAMESTAGE_HEIGHT,smapStage.getMapW_px(),smapStage.getMapH_px(),0.5f,1.2f,smapStage.getIfLoop());
// 创建游戏人物演员
//mapActor = new mapActor(new TextureRegion(mapSprite),0,0,mapW,mapH,GAMESTAGE_WIDTH, GAMESTAGE_HEIGHT); //mapActor = new MapActor(stageId,GAMESTAGE_WIDTH, GAMESTAGE_HEIGHT,mainGame.getAssetManager(),screenId); // 添加演员到舞台
// gameStage.addActor(mapActor);
//stageId不对,应从中获取对应的mapId,ifLoop也是 TODO
ifLoop=true;
// mapActor = new SMapActor(stageId,GAMESTAGE_WIDTH, GAMESTAGE_HEIGHT,mainGame.getAssetManager(),screenId,imgLists);
// gameStage.addActor(mapActor);
//将来以玩家选择国家首都为位置标准 TODO i=1;
for (int u=0;u<ui.size();u++) {
tempX=ui.get(u).getInt("x");tempY=ui.get(u).getInt("y");tempW=ui.get(u).getInt("w");tempH=ui.get(u).getInt("h"); //遍历window的buttons按钮
buttonEs = ui.get(u).getChildByName("buttons").getChildrenByNameRecursively("button"); // 递归遍历,否则的话返回null
for (int b=0,bMax=buttonEs.size;b<bMax;b++) {
//Gdx.app.log("ui测试", button.get("remark")); button = new ImageButton(new TextureRegionDrawable(imgLists.getTextureByName(buttonEs.get(b).get("imgUpName")).getTextureRegion()),new TextureRegionDrawable(imgLists.getTextureByName(buttonEs.get(b).get("imgDownName")).getTextureRegion()),new TextureRegionDrawable(imgLists.getTextureByName(buttonEs.get(b).get("imgDownName")).getTextureRegion()));
button.setSize(buttonEs.get(b).getInt("w")==0?imgLists.getTextureByName(buttonEs.get(b).get("imgUpName")).getTextureRegion().getRegionWidth():buttonEs.get(b).getInt("w")*imgLists.getTextureByName(buttonEs.get(b).get("imgUpName")).getTextureRegion().getRegionWidth()/100, buttonEs.get(b).getInt("h")==0?imgLists.getTextureByName(buttonEs.get(b).get("imgUpName")).getTextureRegion().getRegionHeight():buttonEs.get(b).getInt("h")*imgLists.getTextureByName(buttonEs.get(b).get("imgUpName")).getTextureRegion().getRegionHeight()/100);
button.setPosition(
buttonEs.get(b).getInt("x")*gameStage.getWidth()/100+button.getWidth()/2>gameStage.getWidth()?gameStage.getWidth()-button.getWidth():buttonEs.get(b).getInt("x")*gameStage.getWidth()/100-button.getWidth()/2<0?0:buttonEs.get(b).getInt("x")*gameStage.getWidth()/100-button.getWidth()/2,
buttonEs.get(b).getInt("y")*gameStage.getWidth()/100+button.getHeight()/2>gameStage.getHeight()?gameStage.getHeight()-button.getHeight():buttonEs.get(b).getInt("y")*gameStage.getHeight()/100-button.getHeight()/2<0?0:buttonEs.get(b).getInt("y")*gameStage.getHeight()/100-button.getHeight()/2);
tempMap=new HashMap();
tempMap.put("FUNCTION_ID", buttonEs.get(b).get("functionId"));
tempMap.put("ID", i);
i++;
function(tempMap);
gameStage.addActor(button);
Gdx.input.setInputProcessor(gameStage);
}
}
//文字示例
label=new Label("FPS:"+Gdx.graphics.getFramesPerSecond(),new LabelStyle(mainGame.getFont(), null)); label.setWidth(200);//设置每行的宽度
label.setWrap(true);//开启换行
label.setPosition(20, 40); gameTimeLabel=new Label(smapStage.getsMapDAO().getTime().getTime(),new LabelStyle(mainGame.getFont(), null));
gameTimeLabel.setPosition(GAMESTAGE_WIDTH/2, GAMESTAGE_HEIGHT*0.95f); gameStage.addActor(label);
gameStage.addActor(gameTimeLabel); processorEvent = new InputProcessorEvent();
mapListener=new MapListener(); //Gdx.app.log("平台", Gdx.app.getType().toString());
switch (Gdx.app.getType()) {
case Desktop:// Code for Desktop applicationbreak;
multiplexer.addProcessor(processorEvent);
case Android:// Code for Android applicationbreak;
multiplexer.addProcessor(new GestureDetector(mapListener));
case WebGL:// Code for WebGL applicationbreak;
multiplexer.addProcessor(processorEvent);
default:// Unhandled (new?) platform applicationbreak;
multiplexer.addProcessor(processorEvent);
multiplexer.addProcessor(new GestureDetector(mapListener));
}
Gdx.input.setInputProcessor(multiplexer); } @Override
public void render(float delta) { handleInput(); smapStage.draw();
smapStage.act(); gameStage.draw();
gameStage.act();
//Gdx.app.log("FPS:", Gdx.graphics.getFramesPerSecond().toString); javaHeap=(Math.round(Gdx.app.getJavaHeap()/1024/1024*10)/10);
if(javaHeap>javaMaxHeap) {
javaMaxHeap=javaHeap;
} label.setText("FPS:"+Gdx.graphics.getFramesPerSecond());
label.getText().appendLine("");
label.getText().appendLine("javaHeap:"+javaHeap+"m/"+javaMaxHeap+"m");
label.getText().appendLine("drawCalls:"+gp.getDrawCalls());
label.getText().appendLine("nativeHeap:"+Math.round(Gdx.app.getNativeHeap()/1024/1024*10)/10+"m");
gameTimeLabel.setText(smapStage.getsMapDAO().getTime().getTime());
//label.getText().appendLine("inputKeyMode:"+mapActor.getKeyMode());//快捷键模式
gp.reset();
} public void dispose() {
super.dispose();
// 场景被销毁时释放资源
if (gameStage != null) {
gameStage.dispose();
gameStage=null;
}
if (smapStage != null) {
smapStage.dispose();
smapStage=null;
}
} //实现的功能
public void function(Map map){
int i=Integer.parseInt(map.get("FUNCTION_ID").toString());
switch(i) {
case 0://返回
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
//Gdx.app.log("点击了第1个按钮", "x:" + x+" y:" + y);
if(game!=null) {
game.showGameScreen(screenId,1);
}
}
});
break;
case 1://加载
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("点击了第2个按钮1", "x:" + x+" y:" + y+" stageId:"+stageId); }
});
break;
case 2://save
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("点击了第3个按钮", "x:" + x+" y:" + y+" stageId:"+stageId); }
});
break;
case 3://上一个时间
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
smapStage.getsMapDAO().getTime().lastTime();
Gdx.app.log("点击了第4个按钮", "x:" + x+" y:" + y+" time:"+smapStage.getsMapDAO().getTime().getTime());
}
});
break;
case 4://下一个时间
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
smapStage.getsMapDAO().getTime().nextTime();
Gdx.app.log("点击了第5个按钮", "x:" + x+" y:" + y+" time:"+smapStage.getsMapDAO().getTime().getTime());
}
});
break;
case 5:
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("点击了第6个按钮", "x:" + x+" y:" + y+" stageId:"+stageId);
}
});
break;
case 6:
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("点击了第7个按钮", "x:" + x+" y:" + y+" stageId:"+stageId); }
});
break;
default://查询绘制省区
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("点击了默认按钮", "x:" + x+" y:" + y);
}
});
break;
}
} public void resize(int width, int height) {
// use true here to center the camera
// that's what you probably want in case of a UI
gameStage.getViewport().update(width, height, false);
} //电脑
class InputProcessorEvent implements InputProcessor { @Override
public boolean keyDown(int keycode) {
/*if (keycode == Keys.BACK) {
// 处理返回事件
} else if (keycode == Keys.MENU) {
// 处理菜单事件
}*/
return true; // 如果此处设置为false那么不会执行key up
} @Override
public boolean keyUp(int keycode) {
return true;
}
@Override
public boolean keyTyped(char character) { // 可以输出按键的字母和数字,不过貌似不好使
return true;
} @Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return true;
} @Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
return true;
} @Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return true;
} @Override
public boolean mouseMoved(int screenX, int screenY) {
cx=screenX;
cy=screenY;
return true;
} @Override
public boolean scrolled(int amount) { if(amount>0) {
smapStage.setDrawLoop(cam.setZoomForMouse(cx,cy,-0.01f));
//((OrthographicCamera) smapStage.getCamera()).zoom -=0.01f;
// Gdx.app.log("scrolled","zoom:"+smapStage.getZoom()+" moveX:"+smapStage.getMoveX()+" moveY:"+smapStage.getMoveY()); //gameStage.setZoom(gameStage.getZoom()+0.01f,cx,cy);
//if(smapStage.setZoom(smapStage.getZoom()+0.01f,cx,cy)){ }
}else {
smapStage.setDrawLoop(cam.setZoomForMouse(cx,cy,0.01f));
//((OrthographicCamera) smapStage.getCamera()).zoom +=0.01f; //gameStage.setZoom(gameStage.getZoom()-0.01f,cx,cy);
//gameStage.getCamera().view.setToScaling(gameStage.getCamera().view.getScaleX()-0.01f,gameStage.getCamera().view.getScaleY()-0.01f,gameStage.getCamera().view.getScaleZ());
//if(smapStage.setZoom(smapStage.getZoom()-0.01f,cx,cy)){ } // ((OrthographicCamera) smapStage.getCamera()).translate(smapStage.getMoveX(),smapStage.getMoveY(),0 ); // Gdx.app.log("scrolled","zoom:"+smapStage.getZoom()+" moveX:"+smapStage.getMoveX()+" moveY:"+smapStage.getMoveY()); }
//Gdx.app.log("", mapActor.getZoom()+"");
return true;
} }
//触摸屏 class MapListener implements GestureListener{ @Override
public boolean touchDown(float x, float y, int pointer, int button) {
//Gdx.app.log("touchDown", "x:" + x+" y:" + y);
return false;
} @Override
public boolean tap(float x, float y, int count, int button) {
//Gdx.app.log("tap", "x:" + x+" y:" + y);
return false;
} @Override
public boolean longPress(float x, float y) {
Gdx.app.log("longPress", "x:" + x+" y:" + y);
return false;
} @Override
public boolean fling(float velocityX, float velocityY, int button) {
Gdx.app.log("fling", "velocityX:" + velocityX+" velocityY:" + velocityY);
return false;
} @Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
Gdx.app.log("touchDown", "x:" + x+" y:" + y);
return false;
} @Override
public boolean panStop(float x, float y, int pointer, int button) {
//Gdx.app.log("touchDown", "x:" + x+" y:" + y);
return false;
} @Override
public boolean zoom (float originalDistance, float currentDistance){
Gdx.app.log("zoom", "originalDistance:" + originalDistance+" currentDistance:" + currentDistance);
//TODO 触摸缩放事件
return false;
} @Override
public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer){
Gdx.app.log("pinch", "");
return false;
}
@Override
public void pinchStop () {
Gdx.app.log("pinchStop", "");
} } private void handleInput() { // justTouched 是开始按下手指的第一个点。
if (Gdx.input.justTouched() && isTouching == false) {
isTouching = true;
touchBaseX = Gdx.input.getX(0);
touchBaseY = Gdx.input.getY(0);
//touchBaseX += cam.position.x - GAMESTAGE_WIDTH / 2;
//Gdx.app.log("触摸", "1"); // isTouched 是结束时,手指按下的点。
} else if (Gdx.input.isTouched(0) && isTouching == true) {
touch_X = Gdx.input.getX(0);
touch_Y = Gdx.input.getY(0);
moveX=(touchBaseX-touch_X)/20;
moveY=(touch_Y-touchBaseY)/20;
if(moveX>50) {
moveX=50;
}
if(moveX<-50) {
moveX=-50;
}
if(moveY>50) {
moveY=50;
}
if(moveY<-50) {
moveY=-50;
}
smapStage.setDrawLoop(cam.translateCam(moveX, moveY));
}else {
isTouching =false;
}
/*
if (Gdx.input.isKeyPressed(Input.Keys.A)) {
mapActor.setZoom(mapActor.getZoom()+0.0001f,cx,cy);
}
if (Gdx.input.isKeyPressed(Input.Keys.Q)) {
mapActor.setZoom(mapActor.getZoom()-0.0001f,cx,cy);
}*/ /*if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
gameStage.setX(gameStage.getX()+1);
}
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
gameStage.setX(gameStage.getX()-1);
}
if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
gameStage.setY(gameStage.getY()+1);
}
if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
gameStage.setY(gameStage.getY()-1);
}*/
} public int getStageId() {
return stageId;
} public void setStageId(int stageId) {
this.stageId = stageId;
} /* private void moveCam(float x,float y){
x=((OrthographicCamera) smapStage.getCamera()).position.x+x;
y= ((OrthographicCamera) smapStage.getCamera()).position.y+y;
y=Math.max(0,y);
y=Math.min(y,smapStage.getMapH_px());
//((OrthographicCamera) smapStage.getCamera()).translate(x,y,0 );
((OrthographicCamera) smapStage.getCamera()).position.x=x;
((OrthographicCamera) smapStage.getCamera()).position.y=y;
Gdx.app.log("moveCam"," x:"+((OrthographicCamera) smapStage.getCamera()).position.x+" y:"+((OrthographicCamera) smapStage.getCamera()).position.y);
}*/ }

SMapScreen

SMapstage,用来容纳游戏元素的容器

package com.zhfy.game.screen.stage;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Pool;
import com.badlogic.gdx.utils.Pools;
import com.badlogic.gdx.utils.XmlReader;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.zhfy.game.MainGame;
import com.zhfy.game.config.ResConfig;
import com.zhfy.game.framework.GameFramework;
import com.zhfy.game.framework.tool.BTLTooL;
import com.zhfy.game.model.content.BTLDAO;
import com.zhfy.game.model.content.MapBinDAO;
import com.zhfy.game.model.content.SMapDAO;
import com.zhfy.game.model.framework.TextureRegionListDAO;
import com.zhfy.game.screen.actor.SMapActor;
import com.zhfy.game.screen.actor.framework.ImageActor;
import com.zhfy.game.screen.actor.map.MapImageActor;
import com.zhfy.game.screen.stage.base.BaseStage; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; public class SMapStage extends BaseStage { //实现功能
//地图对象与stage分离 SMapActor smapBg;
SMapDAO sMapDAO;
BTLDAO sMapBin;
int screenId;
TextureRegionListDAO imgLists; private boolean ifLoop;// 是否循环
private boolean drawLoop;
private float x;//玩家起始位置
private float y;
private float lastX;
private float lastY; private float zoom;
private float zoomMax;
private float zoomMin;
private float xMin;
private float yMin;
private float xMax;
private float yMax;
private int mapW_px;
private int mapH_px;
private MapBinDAO mapBinDAO; private HashMap playerMap;
private XmlReader.Element defStage;
private XmlReader.Element defHistory; private GameFramework gameFramework;
private MapImageActor battleMark; /** 当前界面可见的所有图像集合 */
private final ArrayList<MapImageActor> mapImageActorList = new ArrayList<MapImageActor>();
/** 图像对象缓存池, 因为需要频繁生成和移除, 所有使用对象池减少对象的频繁创建 */
private Pool<MapImageActor> mapImageActorPool; private List<Integer> newBattleList; public SMapStage(MainGame mainGame, Viewport viewport, int screenId, TextureRegionListDAO imgLists) {
super(mainGame, viewport);
this.screenId=screenId;
this.imgLists=imgLists;
this.gameFramework=mainGame.getGameFramework();
init();
} private void init() {
//getMainGame().getLogTime().reStar(); defStage = gameFramework.getDefStageByStageId(getMainGame().getStageId());
ifLoop = defStage.getBoolean("ifLoop"); playerMap=new HashMap();//TODO
playerMap.put("playerCountry",0);
playerMap.put("playerScore",0);
playerMap.put("gameMode",0); StringBuilder path=new StringBuilder("sav/");
path.append(defStage.get("name")).append(".bin");
boolean ifInit = Gdx.files.local(path.toString()).exists();
//boolean ifInit = Gdx.files.local("sav/"+defStage.get("name")+".bin").exists();
if(!ifInit){//如果不存在则生成
for(XmlReader.Element his:ResConfig.Config.DEF_HISTORY.getChildrenByName("hostory")){
if(his.getInt("id")==defStage.getInt("id")){
defHistory=his;
}
} BTLDAO historyDao = gameFramework.getBinDaoById(defHistory.get("name"), ResConfig.Rules.RULE_FB1_HISTORY);
mapBinDAO = gameFramework.getMapDaoByMapId(historyDao.getBm0().getBm0_2());
sMapDAO=new SMapDAO(historyDao,mapBinDAO,defHistory.getInt("mapId"),playerMap,defStage.getInt("year"),defStage.get("name"));
sMapBin=sMapDAO.getSmapBin(); historyDao=null;
}else{ try {
//sMapBin = BTLTooL.LoadBtl(ResConfig.Rules.RULE_FB1_SMAP,Gdx.files.local("sav/" +defStage.get("name") + ".bin").readBytes());
sMapBin = BTLTooL.LoadBtl(ResConfig.Rules.RULE_FB1_SMAP,Gdx.files.local(path.toString()).readBytes()); } catch (Exception e) {
e.printStackTrace();
}
mapBinDAO = gameFramework.getMapDaoByMapId(sMapBin.getBm0().getBm0_2());
//BTLDAO smapBin,MapBinDAO mapBin,,Map map
sMapDAO=new SMapDAO(sMapBin,playerMap);
}
//Gdx.app.log("ifInit",defStage.get("name")+":"+ifInit); smapBg=new SMapActor(getMainGame(),screenId,sMapDAO.getRegionColors());
addActor(smapBg); //TODO 玩家起始位置
this.x=10;
this.y=10;
this.zoom = 1f;
this.zoomMax = 1.2f;
this.zoomMin = 0.8f;
// 实际宽高
this.mapW_px = smapBg.gettextureMain().getWidth();
this.mapH_px = smapBg.gettextureMain().getHeight();
this.xMax = mapW_px*this.zoom-getMainGame().getWorldWidth();;
this.yMax = mapH_px*this.zoom-getMainGame().getWorldHeight();
this.yMin = 0;
this.xMin = 0;
drawLoop=false; /*
* 战斗标志
*/
mapImageActorPool = Pools.get(MapImageActor.class, 10);
initBattleMark();
syncPotion();
} @Override
public void dispose() {
super.dispose(); if(smapBg!=null){
smapBg.dispose();
smapBg=null;
}
defStage=null;
defHistory=null;
} public SMapActor getSmapBg() {
return smapBg;
} public void setSmapBg(SMapActor smapBg) {
this.smapBg = smapBg;
} public float getX() {
return x;
}
public void setX(float x) {
if(ifLoop){////判断当前坐标是否需要循环显示右边
if(x<=xMin&&x >= (-xMax * zoom + getMainGame().getWorldWidth())){
drawLoop=false;
//Gdx.app.log("x","1");
}else if(x>xMin){//从起点向左
drawLoop=true; x=(-xMax -getMainGame().getWorldWidth())+x;
// Gdx.app.log("x","2");
}else if(x < (-xMax + getMainGame().getWorldWidth())&&x>(-xMax )){//划入右边,接近循环
drawLoop=true;
// Gdx.app.log("x","3");
}else if(x<=(-xMax -getMainGame().getWorldWidth())) {//划出并还原
drawLoop=false;
x = x + xMax +getMainGame().getWorldWidth();
// Gdx.app.log("x","4");
}/**/
}else {
if (x > xMin) {
x = xMin;
} else if (x < -(xMax)) {
x = -(xMax);
}
}
lastX=this.x;
this.x = x;
syncPotion();
} public float getZoomMax() {
return zoomMax;
} public void setZoomMax(float zoomMax) {
this.zoomMax = zoomMax;
} public float getZoom() {
return zoom;
} public boolean setZoom(float zoom,float cx,float cy) { if(zoom < zoomMax&&zoom > zoomMin){
this.xMax = mapW_px*zoom-getMainGame().getWorldWidth();;
this.yMax = mapH_px*zoom-getMainGame().getWorldHeight();
this.xMin = 0;
this.yMin = 0;
}
if (zoom > zoomMax) {
zoom = zoomMax;
return false; } else if (zoom < zoomMin) {
zoom = zoomMin;
return false;
} else {
setX( x + ((x - cx) * (zoom-this.zoom)) / zoom);
setY( y + ((y - (getMainGame().getWorldHeight()-cy)) * (zoom-this.zoom)) / zoom);
this.zoom = zoom;
return true;
}
} public float getY() {
return y;
}
public void setY(float y) {
if (y > yMin) {
lastY=this.y;
y = yMin;
//Gdx.app.log("y","1");
} else if (y < -yMax) {
lastY=this.y;
y = -yMax;
//Gdx.app.log("y","2");
}
lastY=this.y;
this.y = y;
syncPotion();
//Gdx.app.log("y","Y"+y+" yMax:"+yMax+" zoom:"+zoom);
} public SMapDAO getsMapDAO() {
return sMapDAO;
} public void setsMapDAO(SMapDAO sMapDAO) {
this.sMapDAO = sMapDAO;
} public BTLDAO getsMapBin() {
return sMapBin;
} public void setsMapBin(BTLDAO sMapBin) {
this.sMapBin = sMapBin;
} public int getMapW_px() {
return mapW_px;
} public void setMapW_px(int mapW_px) {
this.mapW_px = mapW_px;
} public int getMapH_px() {
return mapH_px;
} public void setMapH_px(int mapH_px) {
this.mapH_px = mapH_px;
} public void initBattleMark(){
//初始化新增
initNewBattleMark();
//绘制新增
if(newBattleList.size()<1){
Gdx.app.log("SMapStage initBattleMark","无战斗地区");
return;
}
for(int i=0,iMax=newBattleList.size(),j;i<iMax;i++){
j=sMapDAO.getRegionSortMap().get(newBattleList.get(i));
if( sMapDAO.getSmapBin().getBm1().get(j).getBm1_6()==1){
//1战斗中
MapImageActor battleMarketActor = mapImageActorPool.obtain();
battleMarketActor.init(imgLists.getTextureByName(ResConfig.Image.BATTLE_MARK_1),smapBg.getMapW_px(),smapBg.getMapH_px(),smapBg.getW(),newBattleList.get(i));
battleMarketActor.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("12", "x:" + x+" y:" + y);
}
});
addActor(battleMarketActor);
mapImageActorList.add(battleMarketActor);
}else if(sMapDAO.getSmapBin().getBm1().get(j).getBm1_6()==2){
//2可参战
MapImageActor battleMarketActor = mapImageActorPool.obtain();
battleMarketActor.init(imgLists.getTextureByName(ResConfig.Image.BATTLE_MARK_2),smapBg.getMapW_px(),smapBg.getMapH_px(),smapBg.getW(),newBattleList.get(i));
battleMarketActor.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("13", "x:" + x+" y:" + y);
}
});
addActor(battleMarketActor);
mapImageActorList.add(battleMarketActor);
}else{
Gdx.app.error("initBattleMark",newBattleList.get(i)+":"+j+":"+sMapDAO.getSmapBin().getBm1().get(j).getBm1_6());
}
}
} //清除图像并返回需创建的id集合
private void initNewBattleMark(){
if(mapImageActorList.size()==0){
newBattleList=sMapDAO.getBattleRegions();
}else {
newBattleList.clear();
Iterator<MapImageActor> it = mapImageActorList.iterator();
MapImageActor bmActor = null;//BattleMarket
while (it.hasNext()) {
bmActor = it.next();
if (!sMapDAO.getBattleRegions().contains(bmActor.getId())) {
// 从舞台中清除图像
getRoot().removeActor(bmActor);
// 从集合中清除该对象
it.remove();
// 回收对象(放回到对象池中)
mapImageActorPool.free(bmActor);
bmActor.clearListeners();
Gdx.app.log("clearListener","");
} else {
newBattleList.add(bmActor.getId());
}
}
}
}
// 同步移动,现在改为相机,只负责通知是否循环地图
private void syncPotion(){
smapBg.setDrawLoop(drawLoop);
//smapBg.syncPotion(getX(),getY(),getZoom(),drawLoop);
for(MapImageActor mapImage:mapImageActorList){
if(mapImage.isIfEable()){
mapImage.syncPotion(drawLoop);
}
}
} public void setDrawLoop(boolean drawLoop) {
this.drawLoop = drawLoop;
syncPotion();
} public boolean getIfLoop() {
return ifLoop;
}
}

SMapStage

对场景的相机进行封装

package com.zhfy.game.model.framework;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.OrthographicCamera; public class CamerDAO { private boolean ifLoop;
private float camZoomMax;
private float camZoomMin;
private float camXMin;
private float camYMin;
private float camXMax;
private float camYMax;
private float vw;
private float vh;
private OrthographicCamera camera; public CamerDAO (OrthographicCamera camera,float viewW,float viewH,int mapW_px,int mapH_px,float zoomMin,float zoomMax,boolean ifLoop){
this.camera=camera;
vw=viewW;
vh=viewH;
camXMin=viewW/2;
camYMin=viewH/2;
camXMax=mapW_px;
camYMax=mapH_px;
camZoomMax=zoomMax;
camZoomMin=zoomMin;
this.ifLoop=ifLoop;
} public boolean translateCam(float x,float y){
return setPotion(camera.position.x+x,camera.position.y+y);
// camera.translate(x,y,0);
}
//!对x,y进行检查
public boolean setPotion(float x,float y){
boolean state=false;//是否是循环
if(ifLoop) {
if(x>=camXMin*camera.zoom&&x<=(camXMax+camXMin*camera.zoom-vw*camera.zoom)){//原
//Gdx.app.log("setPotion0","x:"+x+" y:"+y+" state:"+state);
}else if(x<camXMin*camera.zoom){//起点向左
state=true;
x=(camXMax+camXMin*camera.zoom-vw*camera.zoom)+camXMin*camera.zoom+x;
//Gdx.app.log("setPotion1","x:"+x+" y:"+y+" state:"+state);
}else if(x>(camXMax+camXMin*camera.zoom-vw*camera.zoom)&&x<(camXMax+camXMin*camera.zoom-vw*camera.zoom)+camXMax){///划入右边,接近循环
state=true;
//Gdx.app.log("setPotion2","x:"+x+" y:"+y+" state:"+state);
}else if(x>=(camXMax+camXMin*camera.zoom-vw*camera.zoom)-camXMax){//划出并还原
state=false;
x=x-(camXMax+camXMin*camera.zoom-vw*camera.zoom)-camXMin*camera.zoom;
//Gdx.app.log("setPotion3","x:"+x+" y:"+y+" state:"+state);
}
}else{
if(x<camXMin*camera.zoom){
x=camXMin*camera.zoom;
}else if(x>(camXMax+camXMin*camera.zoom-vw*camera.zoom)){
x=(camXMax+camXMin*camera.zoom-vw*camera.zoom);
}
}
if(y<camYMin*camera.zoom){
y=camYMin*camera.zoom;
}else if(y>(camYMax+camYMin*camera.zoom-vh*camera.zoom)){
y=(camYMax+camYMin*camera.zoom-vh*camera.zoom);
}
camera.position.x=x;
camera.position.y=y;
//Gdx.app.log("setPotion","x:"+x+" y:"+y+" state:"+state);
return state;
} //中心点缩放 根据鼠标中心点缩放
public boolean setZoomForMouse(float cx,float cy,float zoomV){
camera.zoom +=zoomV;
//Gdx.app.log("Zoom","cx:"+cx+" cy:"+cy+" zoomV:"+zoomV);
return setPotion(camera.position.x+(vw/2-cx)*zoomV,camera.position.y-(vh/2-cy)*zoomV);// -(cy-vh)
} public void setZoom(float v){
camera.zoom +=v;
} public float getCamZoomMax() {
return camZoomMax;
} public void setCamZoomMax(float camZoomMax) {
this.camZoomMax = camZoomMax;
} public float getCamZoomMin() {
return camZoomMin;
} public void setCamZoomMin(float camZoomMin) {
this.camZoomMin = camZoomMin;
} public float getCamXMin() {
return camXMin;
} public void setCamXMin(float camXMin) {
this.camXMin = camXMin;
} public float getCamYMin() {
return camYMin;
} public void setCamYMin(float camYMin) {
this.camYMin = camYMin;
} public float getCamXMax() {
return camXMax;
} public void setCamXMax(float camXMax) {
this.camXMax = camXMax;
} public float getCamYMax() {
return camYMax;
} public void setCamYMax(float camYMax) {
this.camYMax = camYMax;
} public OrthographicCamera getCamera() {
return camera;
} public void setCamera(OrthographicCamera camera) {
this.camera = camera;
}
}

CamerDAO

SMapStage的演员:

1.战斗标记(主要监听它)

package com.zhfy.game.screen.actor.map;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Pool;
import com.zhfy.game.config.ResConfig;
import com.zhfy.game.framework.GameMap;
import com.zhfy.game.model.content.DefDAO;
import com.zhfy.game.model.framework.TextureRegionDAO;
import com.zhfy.game.model.framework.TextureRegionListDAO; import java.util.Map; /**
* 游戏中的演员,适用于;六边形地图内
*
*/
public class MapImageActor extends Actor implements Pool.Poolable { private boolean ifEable;
private TextureRegion region;
private float sourceX;//初始位置
private float sourceY;//初始位置 private float zoom; private int mapW_px;//横向移动需要的值 像素
private int mapH_px;
private int mapW;//格子数,辅助计算坐标
private boolean drawLoop;
private int id; public MapImageActor(TextureRegionDAO regionDAO, int mapW_px,int mapH_px,int mapW,int id) {
ifEable=false;
this.mapW_px=mapW_px;
this.mapH_px=mapH_px;
this.mapW=mapW;
this.region=regionDAO.getTextureRegion();;
this.drawLoop=false;
setSize(this.region.getRegionWidth(), this.region.getRegionHeight());
this.id=id;
initPotionById(regionDAO.getRefx(),regionDAO.getRefy());
ifEable=true;
} public MapImageActor(){} public void init(TextureRegionDAO regionDAO, int mapW_px, int mapH_px,int mapW, int id){
//imgLists.getTextureByName("task_battle")
ifEable=false;
this.mapW_px=mapW_px;
this.mapH_px=mapH_px;
this.mapW=mapW;
this.zoom=1f;
this.region=regionDAO.getTextureRegion();
this.drawLoop=false;
setSize(this.region.getRegionWidth(), this.region.getRegionHeight());
this.id=id;
initPotionById(regionDAO.getRefx(),regionDAO.getRefy());
setWidth(region.getRegionWidth());
setHeight(region.getRegionHeight());
setX(sourceX*zoom+getX());
setY(sourceY*zoom+getY());
//TODO
//this.x=300;
//this.y=300;
ifEable=true;
//Gdx.app.log("imgActor"," x:"+getX()+" y:"+getY());
} //同步坐标
public void syncPotion(boolean drawLoop){
if(ifEable){
//this.x=sourceX*zoom+x;
//this.y=-sourceY*zoom+y;
//this.zoom=zoom;
this.drawLoop=drawLoop;
}else{
Gdx.app.error("MapImageActor initError","id"+id);
} } /*public ImageActor(TextureRegion region) {
this.region = region;
this.drawLoop=false;
this.mapW=0;
setSize(this.region.getRegionWidth(), this.region.getRegionHeight());
} public ImageActor(Texture texture) {
this.region = new TextureRegion(texture);
this.drawLoop=false;
this.mapW=0;
setSize(this.region.getRegionWidth(), this.region.getRegionHeight());
}*/ public TextureRegion getRegion() {
return region;
} public void setRegion(TextureRegion region) {
this.region = region;
if (this.region != null) {
setSize(this.region.getRegionWidth(), this.region.getRegionHeight());
} else {
setSize(0, 0);
}
} @Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
if (region == null || !isVisible()||!isIfEable()) {
return;
} // 备份 batch 原本的 Color
// Color tempBatchColor = batch.getColor(); // 获取演员的 Color
//Color color = getColor(); // 将演员的 Color 结合 parentAlpha 设置到 batch
//batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); // 结合演员的属性绘制表示演员的纹理区域
batch.draw(
region,
getX(), getY(),
getOriginX(), getOriginY(),
getWidth()*zoom, getHeight()*zoom,
getScaleX(), getScaleY(),
getRotation()
);
if(drawLoop){//如果循环,则添加一部分
batch.draw(
region,
getX()+getMapW_px(), getY(),
getOriginX(), getOriginY(),
getWidth()*zoom, getHeight()*zoom,
getScaleX(), getScaleY(),
getRotation()
);
} // 还原 batch 原本的 Color
// batch.setColor(tempBatchColor);
} public float getZoom() {
return zoom;
} public void setZoom(float zoom) {
this.zoom = zoom;
} public int getMapW_px() {
return mapW_px;
} public void setMapW_px(int mapW_px) {
this.mapW_px = mapW_px;
} public boolean isDrawLoop() {
return drawLoop;
} public void setDrawLoop(boolean drawLoop) {
this.drawLoop = drawLoop;
} public boolean isIfEable() {
return ifEable;
} public void setIfEable(boolean ifEable) {
this.ifEable = ifEable;
} public int getMapW() {
return mapW;
} public void setMapW(int mapW) {
this.mapW = mapW;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} @Override
public void reset() {
ifEable=false;
} private void initPotionById(float refx,float refy){
Map<String,Integer> rs= GameMap.getDownleftPotionById(mapW,mapH_px, ResConfig.Map.SMALLMAP_SCALE,id);
this.sourceX=rs.get("sourceX")-refx;
this.sourceY=rs.get("sourceY")-refy;
//Gdx.app.log("initPotionById","id:"+id+" sourceX:"+sourceX+" sourceY:"+sourceY);
} }

MapImageActor

2.小地图

package com.zhfy.game.screen.actor;

import java.util.List;
import java.util.Map; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.PixmapIO;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.zhfy.game.MainGame;
import com.zhfy.game.config.ResConfig;
import com.zhfy.game.framework.ComUtil;
import com.zhfy.game.framework.GameFramework;
import com.zhfy.game.framework.GameMap;
import com.zhfy.game.framework.GameUtil;
import com.zhfy.game.model.content.MapBinDAO;
import com.zhfy.game.model.content.SMapDAO;
import com.zhfy.game.model.framework.Coord;
import com.zhfy.game.model.framework.SpriteDAO;
import com.zhfy.game.model.framework.SpriteListDAO;
import com.zhfy.game.model.framework.TextureRegionListDAO; public class SMapActor extends Actor {
//加载history来生成剧本 // 本类用来存放背景地图,获取地图范围,移动,缩放背景地图,确定点击位置等,以及环状地图
//private DefMap defMap;
private Pixmap pixmap;// 临时画布
//private MapBinDAO mapBinDAO; private Texture textureMain;// 主图
private Texture textureCountry;
private Pixmap pixmapCountry; private Sprite spriteMain;// 主图
private Sprite spriteCountry; private int w;
private int h; private int mapId;
private float x;
private float y;
private float zoom;
private int mapW_px;
private int mapH_px;
private boolean drawLoop; private float vx;
private float vy; private AssetManager am;
private int screenId;
private boolean ifNeedUnload;//是否需要卸载,在资源加载完后卸载,如果未加载完退出,在退出时顺带清理资源 private int mapTimeMax; public float getVx() {
return vx;
} public void setVx(float vx) {
this.vx = vx;
} public float getVy() {
return vy;
} public void setVy(float vy) {
this.vy = vy;
} //private DrawListDAO drawBattleList;
//private DrawDAO drawBattle;
private int drawX,drawY;
private int drawI;
// 颜色层
//private Texture textureGrid;
private SpriteDAO spriteGrid;
private SpriteListDAO spriteGrids;
private int gw;
private int gh;
//private TextureRegionDAO battleTaskTR; public SMapActor(MainGame game, int screenId, Map regionColors) {
super();
this.am=game.getAssetManager();
ifNeedUnload=false;
this.screenId=screenId; this.x=0;
this.y=0;
this.zoom=1f;
drawLoop=false;
{
// 绘制主要图
textureMain= (GameMap.drawSmallMapAndClearPixmap2(game.getStageId(),am));
spriteMain= new Sprite(textureMain);
}
this.mapW_px = textureMain.getWidth();
this.mapH_px = textureMain.getHeight();
this.w = game.getMapBinDao().getMapWidth();
this.h = game.getMapBinDao().getMapHeight(); /*if(!ifInit)*/{//绘制一个区域图
// 绘制画布转为装饰
long startTime = System.currentTimeMillis();
pixmapCountry = GameMap.createPixmap((int)(w*ResConfig.Map.SMALLMAP_SCALE),(int)(h*ResConfig.Map.SMALLMAP_SCALE)); GameMap.getPixmapByHistoryForLegionColor(game.getMapBinDao(),pixmapCountry,ResConfig.Map.SMALLMAP_SCALE,game.getMapBinDao().getCoastGrid(), ResConfig.Config.COUNTRY_COLORS,regionColors); //PixmapIO.writePNG(Gdx.files.external("textureColor.png"), pixmapCountry);
textureCountry=new Texture(pixmapCountry);
long endTime = System.currentTimeMillis(); //获取结束时间
//Gdx.app.log("色图构建", " 运行时间:"+(endTime - startTime) + "ms");
spriteCountry= new Sprite(textureCountry);
spriteCountry.setSize(textureMain.getWidth(),textureMain.getHeight());
//PixmapIO.writePNG(Gdx.files.local("sav/"+sMapName+".png"), pixmapCountry);
}/*else{
textureCountry=new Texture(Gdx.files.local("sav/"+sMapName+".png"));
spriteCountry= new Sprite(textureCountry);
spriteCountry.setSize(textureMain.getWidth(),textureMain.getHeight());
}*/ //pixmapCountry=GameMap.updateColorByRegion(mapBinDAO,pixmapCountry, ResConfig.Map.SMALLMAP_SCALE,sMapDAO.getBattleRegions(),coastGrid,legionColors,sMapDAO.getRegionColors());
//textureCountry.draw(pixmapCountry,0,0); /*{
// 绘制画布转为装饰
pixmap = GameMap.createPixmap((int)(w*ResConfig.Map.SMALLMAP_SCALE),(int)(h*ResConfig.Map.SMALLMAP_SCALE));
pixmap=GameMap.coverImgByPtimgId(pixmap, 2);
gameFramework.getPixmapDecorateByDao(pixmap, mapBinDAO,am,ResConfig.Map.SMALLMAP_SCALE);
PixmapIO.writePNG(Gdx.files.external("textureDecorate.png"), pixmap);
pixmap.dispose();
}*/ setSize(spriteMain.getWidth(), spriteMain.getHeight());
/**/
/*addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) { //随机绘图
pixmapCountry=GameMap.updateColorByRegion(mapBinDAO,pixmapCountry, ResConfig.Map.SMALLMAP_SCALE, ComUtil.getNByListRand(regionGrid,3),coastGrid,legionColors,sMapDAO.getRegionColors());
textureCountry.draw(pixmapCountry,0,0); }
});*/
//battleTaskTR=imgLists.getTextureByName("task_battle");
//drawBattleList=new DrawListDAO();
//createBattle();
} @Override
public void act(float delta) {
super.act(delta);
} @Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
if (spriteMain == null || !isVisible()) {
return;
} {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.draw(spriteMain, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(),
getZoom(), getZoom(), getRotation());
batch.draw(spriteCountry, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(),
getZoom(), getZoom(), getRotation()); if(drawLoop){
//Color oldColor=batch.getColor();
//batch.setColor(Color.RED);
batch.draw(spriteMain, getX()+mapW_px*this.zoom, getY(), getOriginX(), getOriginY(), getWidth(), getHeight(),
getZoom(), getZoom(), getRotation());
batch.draw(spriteCountry, getX()+mapW_px*this.zoom, getY(), getOriginX(), getOriginY(), getWidth(), getHeight(),
getZoom(), getZoom(), getRotation());
//batch.setColor(oldColor);
} } } @Override
public float getX() {
return x;
} @Override
public void setX(float x) {
this.x = x;
} @Override
public float getY() {
return y;
} @Override
public void setY(float y) {
this.y = y;
} public float getZoom() {
return zoom;
} public void setZoom(float zoom) {
this.zoom = zoom;
} public int getW() {
return w;
} public void setW(int w) {
this.w = w;
} public int getH() {
return h;
} public void setH(int h) {
this.h = h;
} // 将↓→坐标(左上角为0,0,越向右下越大)转为←↓act坐标(左下角为0,0,越向右上越小)
public float getActXCoordByImgX(float print_x) {
return (-print_x);
} public float getActYCoordByImgY(float print_y) {
return (print_y - spriteMain.getHeight());
} // 将←↓act坐标(左下角为0,0,越向右上越小)转化为↓→坐标(左上角为0,0,越向右下越大)
// 将↓→坐标(左上角为0,0,越向右下越大)转为←↓act坐标(左下角为0,0,越向右上越小)
public float getImgXCoordByActX(float print_x) {
if(print_x!=0f) {
return (-print_x);
}else {
return 0f;
}
} public float getImgYCoordByActY(float print_y) {
return (spriteMain.getHeight() + print_y);
} // 清理5张图层
public void dispose() {
if(pixmapCountry!=null){
pixmapCountry.dispose();
pixmapCountry=null;
}
if (textureMain != null) {
textureMain.dispose();
textureMain=null;
}
if (textureCountry!=null){
textureCountry.dispose();
textureCountry=null;
}
if (ifNeedUnload) {
GameUtil.unloadSingleResByScreenId(am, screenId);
} } public Pixmap getPixmap() {
return pixmap;
} public void setPixmap(Pixmap pixmap) {
this.pixmap = pixmap;
} public Texture gettextureMain() {
return textureMain;
} public void settextureMain(Texture textureMain) {
this.textureMain = textureMain;
} public Sprite getspriteMain() {
return spriteMain;
} public void setspriteMain(Sprite spriteMain) {
this.spriteMain = spriteMain;
} public SpriteDAO getSpriteGrid() {
return spriteGrid;
} public void setSpriteGrid(SpriteDAO spriteGrid) {
this.spriteGrid = spriteGrid;
} public int getGw() {
return gw;
} public void setGw(int gw) {
this.gw = gw;
} public int getGh() {
return gh;
} public void setGh(int gh) {
this.gh = gh;
} public SpriteListDAO getSpriteGrids() {
return spriteGrids;
} public void setSpriteGrids(SpriteListDAO spriteGrids) {
this.spriteGrids = spriteGrids;
} /*public void createBattle(){
drawBattleList.clear();
for(int i: sMapDAO.getBattleRegions()){
drawBattle=new DrawDAO();
drawBattle.setTextureName("task_battle");
GameMap.getCenterPotionById(mapBinDAO,drawX,drawY,ResConfig.Map.SMALLMAP_SCALE,mapBinDAO.getIdByRegionId(i)); drawBattle.setLx_px(drawX);
drawBattle.setLx_px(drawY);
drawBattleList.add(drawBattle);
}
}*/ public boolean isDrawLoop() {
return drawLoop;
} public void syncPotion(float x, float y, float zoom,boolean drawLoop){
this.x=x;
this.y=y;
this.zoom=zoom;
this.drawLoop=drawLoop;
} public int getMapW_px() {
return mapW_px;
} public int getMapH_px() {
return mapH_px;
} public void setDrawLoop(boolean drawLoop) {
this.drawLoop = drawLoop;
}
}

SMapActor

最新文章

  1. 阿里云推送SDK在某些机型(某米为主)下崩溃问题的解决方法
  2. Java Thread 的使用
  3. Silverlight动态生成控件实例
  4. MVC 实体字段自定义验证
  5. 【leetcode】Reverse Nodes in k-Group
  6. 学习mongo系列(十)MongoDB 备份(mongodump)与恢复(mongorerstore) 监控(mongostat mongotop)
  7. select * 所有字段时如何巧妙的使用覆盖索引
  8. Oracle数据库SQL优化
  9. Linux下DNS服务器的基本搭建
  10. C Primer Plus 第3章 数据和C 编程练习
  11. 8.3 MPI
  12. ACM2075_A/B
  13. 当一个线程进入一个对象的一个synchronized方法后,其它线程是否可进入此对象的其它方法(转)
  14. Struts2学习笔记(十)——自定义拦截器
  15. iOS 友盟推送,应用内推送启动图推送闪动黑屏,插屏推送方法报错
  16. asp.net core 自定义中间件
  17. BizTalk Map 累积连接字符串
  18. JAVA单链表的实现-不带头结点但带有尾指针
  19. 初识Netty
  20. scala编程第15章

热门文章

  1. Leetcode199. Binary Tree Right Side View二叉树的右视图
  2. Mathtype部分数学符号不能显示,只能显示方框时的解决办法
  3. Ubuntu18.04 + win10双系统下时间问题
  4. hdu 1269 (强联通分量Tarjan入门)
  5. Xshell 、PuTTY 复制文件到Linux
  6. 在centos 6.3系统下安装java、tomcat环境的方法与步骤(方法经过验证,可安装成功)
  7. day36 07-Hibernate抓取策略:many-to-one上的抓取策略
  8. echarts 重新渲染(重新绘制,重新加载数据)等
  9. Django 点滴
  10. HTML 实体字符