等距世界滚动Java

时间:2012-05-11 11:03:20

标签: java graphics scroll isometric

所以我创造了一个等距的世界,当你使用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);
    }
}

所以我有2个问题,这是一个很好的,效率很高的方法吗?以及如何修复奇怪的毛刺?这是一段视频:

http://youtu.be/YUn5xCeBInM

1 个答案:

答案 0 :(得分:0)

也许我的回答有点偏,但您可能对libgdx及其IsometricMap样本感兴趣。