问题在于在地图上创建对象。一切都会好的,但突然间我只能在屏幕上创建对象(即图像)。每当我给一个对象一些坐标时,它会占用屏幕的 (0,0) 点,而不是地图。所以我可以在地图上移动我的人(相机工作正常),但例如蜘蛛停留在屏幕上,而不是在地图上。这里初始化对象:
static float PlayerPositionX = 0;
static float PlayerPositionY = 0;
static GameContainer gc;
static StateBasedGame sbg;
//Spider
Monster monster = new Monster();
float shiftXSpider;
float shiftYSpider;
//Player position at the middle of the screen *half of the screen
static float shiftX = PlayerPositionY + (Game.screenWidth/2);
static float shiftY = PlayerPositionX + (Game.screenHeight/2);
static float shiftXMap = PlayerPositionX;
static float shiftYMap = PlayerPositionY;
这是我的地图、蜘蛛和播放器的渲染方法。(当然只是一部分)
worldMap.draw(PlayerPositionX,PlayerPositionY);
player.draw(shiftX,shiftY);
spider.draw(spiderPoint.x, spiderPoint.y);
更新方法:
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
System.out.println(playerPoint.getX() + " " + playerPoint.getY());
playerPoint.x=PlayerPositionX;
playerPoint.y=PlayerPositionY;
Input input = gc.getInput();
monster.Chase(playerPoint.x, playerPoint.y,delta);
// monster.Chase(PlayerPositionX, PlayerPositionY,delta);
// shiftXSpider=monster.getMonsterPositionX();
// shiftYSpider=monster.getMonsterPositionY();
spiderPoint.x=monster.getMonsterPositionX();
spiderPoint.y=monster.getMonsterPositionY();
if(input.isKeyDown(input.KEY_DOWN)) {
player=movingDown;
PlayerPositionY-=delta * .1f;
if(PlayerPositionY<-600) {
PlayerPositionY+=delta * .1f;
}
}
//move up
if(input.isKeyDown(input.KEY_UP)) {
player=movingUp;
PlayerPositionY+=delta * .1f;
if(PlayerPositionY>162) {
PlayerPositionY-=delta * .1f;
}
}
//move right
if(input.isKeyDown(input.KEY_RIGHT)) {
player=movingRight;
PlayerPositionX-=delta * .1f;
if(PlayerPositionX<-840) {
PlayerPositionX+=delta * .1f;
}
}
//move left
if(input.isKeyDown(input.KEY_LEFT)) {
player=movingLeft;
PlayerPositionX+=delta * .1f;
if(PlayerPositionX>324) {
PlayerPositionX-=delta * .1f;
}
}
}