java - Can't add multiple of same rectangle -


i want make multiple of same rectangle on borderpane make walls game. each wall going same , same size. know image works , there no other errors. use following code add rectangles:

public class antz extends application{ public borderpane borderpane;  public scene scene; public image wallimage = new image("/recources/images/walls.png"); public rectangle wall = new rectangle(); public int[][] walls = {{1,0,0,0,0,1,1,1,0,1,0,0,0,0,0,1,0},                   {1,1,1,1,0,1,0,0,0,1,0,1,1,1,0,1,0},                   {0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0},                   {0,1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,0},                   {0,0,0,0,1,0,0,1,0,0,0,1,0,1,1,1,0},                   {1,0,1,1,1,1,0,1,1,1,1,1,0,1,0,0,0},                   {1,0,1,0,0,1,0,0,0,0,0,1,0,0,0,1,1},                   {1,0,1,1,0,1,0,1,0,1,0,0,0,1,0,0,1},                   {1,0,0,0,0,0,0,1,1,1,0,0,1,1,1,0,1},                   {0,0,1,0,1,1,0,1,0,1,1,0,1,0,0,0,0},                   {1,1,1,0,1,0,0,0,0,0,1,0,1,1,0,1,0},                   {1,0,0,0,0,0,1,1,1,0,1,0,0,1,1,1,0},                   {1,0,1,0,1,1,1,0,1,1,1,1,0,0,0,1,0},                   {0,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0},                   {1,0,1,1,1,1,0,1,1,1,0,1,0,1,1,0,1},                   {0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0}};  public static void main(string[] args){     launch(args); }  @override public void start(stage primarystage) throws exception {     buildwindows();     buildwalls();     primarystage.setscene(scene);     primarystage.settitle("formicidae");     primarystage.show();     primarystage.setminheight(550);     primarystage.setminwidth(700);     primarystage.setfullscreenexithint("");     primarystage.setfullscreenexitkeycombination(keycombination.no_match);  }  public void buildwindows() {     borderpane = new borderpane();     borderpane.setstyle("-fx-background-color: #000000;");     scene =  new scene(borderpane, 700, 550); }  public void buildwalls(){     wall = new rectangle(wallimage.getwidth(), wallimage.getheight());     wall.setfill(new imagepattern(wallimage));     for(int = 0;i<walls.length;i++){         for(int j = 0;j<walls[i].length;j++){             if(walls[i][j]==1){                 wall.setx(j*20);                 wall.sety(i*20);                  borderpane.getchildren().add(wall);             }         }     } } } 

i error when ran:

caused by: java.lang.illegalargumentexception: children: duplicate children added: parent = borderpane@4a17c25d[styleclass=root] 

trying add same node twice in pane object not correct behavior. so, have create new 1 every time adding object on pane object.

public void buildwalls(){      wall.setfill(new imagepattern(wallimage));     for(int = 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, tested program image google.

enter image description here

i don't know supposed game here output image.

enter image description here


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -