English 中文(简体)
Isomet World scroll Java
原标题:Isometric world scrolling Java

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光? 这里是录像:

http://youtu.be/YUn5xCeBInM

问题回答

或许我的回答是旁边,但你可能有兴趣了解libgdx及其IsometMap样本。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签