所以我创建了一个等轴测世界,当你使用 WASD 键时它会滚动世界。现在我所做的实际上是根据玩家的移动而不是玩家移动整个世界。这是一个好方法吗?我有一些奇怪的图形故障,在世界的左上角(仅左上角)瓷砖开始出现故障和闪烁......我正在使用 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);
}
}
所以我有 2 个问题,这是一种良好且高效的方法吗?以及如何解决奇怪的故障?这是一个视频: