Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用瓷砖填充正方形_Java_Opengl_Lwjgl_Tiles - Fatal编程技术网

Java 用瓷砖填充正方形

Java 用瓷砖填充正方形,java,opengl,lwjgl,tiles,Java,Opengl,Lwjgl,Tiles,我有一个2D瓷砖游戏,我正在尝试创建笔刷大小。目前,我的代码如下所示: if (isMouseClicked0) { int grid_x = Math.round(mouseX / blockSize); int grid_y = Math.round(mouseY / blockSize); for (int x = 0; x < brushSize; x++) { for (int y = 0; y < brushSize; y++) {

我有一个2D瓷砖游戏,我正在尝试创建笔刷大小。目前,我的代码如下所示:

if (isMouseClicked0) {
    int grid_x = Math.round(mouseX / blockSize);
    int grid_y = Math.round(mouseY / blockSize);
    for (int x = 0; x < brushSize; x++) {
        for (int y = 0; y < brushSize; y++) {
            world.setAt(grid_x, grid_y, b[inventorySelect]);
            grid_x += x;
            grid_y += y;
        }
    }
}
public void setAt(int x, int y, BlockType b) {
    if (x <= Display.getWidth() / blockSize && y <= Display.getHeight() / blockSize) {
        blocks[x][y] = new BaseBlock(b, x * blockSize, y * blockSize);
    }
    render();
}
这将当前生成以下输出:

左上角第一个平铺上方的平铺是我单击鼠标的位置,因此您可以看到下一个平铺没有渲染。我已经做了几个小时了,所以我可能错过了一些简单的东西。有什么帮助吗

编辑:笔刷大小为
2
,因此我应该创建四个平铺<代码>块大小是
32
,这是我的块有多大。

问题在于:

grid_x += x;
grid_y += y;
你基本上是沿着对角线移动。这可能会更好:

    for (int x = 0; x < brushSize; x++) {
        for (int y = 0; y < brushSize; y++) {
            world.setAt(grid_x + x, grid_y + y, b[inventorySelect]);
        }
    }
for(int x=0;x
问题在于:

grid_x += x;
grid_y += y;
你基本上是沿着对角线移动。这可能会更好:

    for (int x = 0; x < brushSize; x++) {
        for (int y = 0; y < brushSize; y++) {
            world.setAt(grid_x + x, grid_y + y, b[inventorySelect]);
        }
    }
for(int x=0;x
哦,哇。真不敢相信我居然没想到!非常感谢。哦,哇。真不敢相信我居然没想到!非常感谢你。