Can't add multiple of same rectangle

∥☆過路亽.° 提交于 2019-12-02 09:55:31
tommybee

Trying to add the same Node twice in the Pane object is not a correct behavior. So, you have to create new one every time adding object on a pane object.

public void buildWalls(){

    wall.setFill(new ImagePattern(wallImage));
    for(int i = 0;i<walls.length;i++){
        for(int j = 0;j<walls[i].length;j++){
            if(walls[i][j]==1){
                wall = new Rectangle(wallImage.getWidth(), wallImage.getHeight());
                wall.setX(j*20);
                wall.setY(i*20);

                borderPane.getChildren().add(wall);
            }
        }
    }
}

Well, I tested the program with some image from google.

I don't know what you are supposed to do with your game but here is the output image.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!