So I created an isometric world and I made that it scrolls the world when you use the W A S D keys. Now what I did is actually move all the world according to the player s movement and not the player. Is this a good way of doing it? I have some weird graphics glitches that at the top left of the world (ONLY TOP LEFT) the tiles start glitching and flashing... I am using Graphics2D..
Here is how I am doing it: The shifter it self:
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);
}
}
tile:
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个问题,这是否是这样做的好、有效的方法? 以及我如何确定ir光? 这里是录像: