所以我创建了一个等距世界,当你使用 W A S D 键时,我让它滚动世界。现在我所做的实际上是根据玩家的移动而不是玩家来移动整个世界。这是个好方法吗?我有一些奇怪的图形故障,在世界的左上角(仅左上角),瓷砖开始出现故障和闪烁......我正在使用Graphics2D。
这是我的做法:它自己的移位器:
public void checkForShift(Player p, World world, GameWindow win) {
//X MOVING
if (p.getEnty().getX()>win.getWidth()/2) {
if (p.getEnty().getX()<world.getWidth()-win.getWidth()/2) {
temp = (p.getEnty().getX()-win.getWidth()/2);
world.subSWidth(temp);
world.subWidth(temp);
world.updateShift(1, temp);
}
}
if (p.getEnty().getX()<win.getWidth()/2) {
if (p.getEnty().getX()>world.getSwidth()+win.getWidth()/2) {
temp = (p.getEnty().getX()-(world.getSwidth()+win.getWidth()/2));
world.addSWidth(temp);
world.addWidth(temp);
world.updateShift(2, temp);
}
}
//Y MOVING
if (p.getEnty().getY()>win.getHeight()/2) {
if (p.getEnty().getY()<world.getHeight()-win.getHeight()/2) {
temp = (p.getEnty().getY()-win.getHeight()/2);
world.subSHeight(temp);
world.subHeight(temp);
world.updateShift(3, temp);
}
}
if (p.getEnty().getY()<win.getHeight()/2) {
if (p.getEnty().getY()>world.getSheight()+win.getHeight()/2) {
temp = (p.getEnty().getY()-(world.getSheight()+win.getHeight()/2));
world.addSHeight(temp);
world.addHeight(temp);
world.updateShift(4, temp);
}
}
}
世界:
public void updateShift(int operation, int amount) {
for(Entity e:ListManager.entityList) {
e.updateShift(operation, amount);
}
for (Chunk c : this.getChunkList()) {
for (Tile t : c.getTileList()) {
t.updateShift(operation, amount);
}
}
}
实体:
public void updateShift(int operation, int amount) {
if (operation == 1) {
SubX(amount);
} else if (operation == 2) {
AddX(amount);
} else if (operation == 3) {
SubY(amount);
} else {
AddY(amount);
}
}
瓷砖:
public void updateShift(int operation, int amount) {
if (operation == 1) {
SubX(amount);
} else if (operation == 2) {
AddX(amount);
} else if (operation == 3) {
SubY(amount);
} else {
AddY(amount);
}
}
所以我有两个问题,这是一种良好且性能高效的方法吗? 我该如何修复奇怪的故障?这是一个视频:
http://youtu.be/YUn5xCeBInM
也许我的回答有点不对劲,但你可能对libgdx及其IsometricMap示例感兴趣。