2012-05-11 56 views
0

因此,我创建了一个等距世界,并使用W A S D键来滚动世界。现在我所做的实际上是根据玩家的移动而不是玩家来移动所有的世界。这是做这件事的好方法吗?我有一些奇怪的图形故障,在世界的左上角(只有左上角)瓷砖开始毛刺和闪烁...我使用Graphics2D ..等距世界滚动Java

这是我如何做到这一点: 移动它自:

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个问题,这是这样做的好和性能有效的方式?以及我如何修复奇怪的毛刺?这里是一个视频:

http://youtu.be/YUn5xCeBInM

回答

0

也许我的反应会是有点过,但你可能有兴趣在libgdx及其IsometricMap样品。

+0

是的,它真的关闭,它不会帮助我..谢谢反正 – Trixmix

+0

我尝试了一些东西了,没有帮助任何人知道如何解决它? – Trixmix