Premetto che ho iniziato da un annetto a programmare ma ho 15 anni e non sto seguendo nessun corso
Ho iniziato a programmare un piccolo gioco ma ho un grosso problema a gestire l'ordine dei rendering
Ovvero ho bisogno che faccia prima il rendering degli oggetti con la variabile y più piccola e poi quelli con la y più grande
Sto lavorando con una LinkedList e ho provato a mettere in ordine gli oggetti con questo codice
L'ho preso da un vecchio codice però che utilizzava un arraycodice:boolean flag=true; GameObject tempObj1; GameObject tempObj2; public void DepthHandler(LinkedList<GameObject> list) { while(flag) { for (int n=0;n<list.size()-1;n++) { tempObj1=list.get(n); tempObj2=list.get(n+1); flag=false; System.out.println("trying..." + tempObj1.y + tempObj2.y); if (tempObj1.y>tempObj2.y) { flag=true; list.set(n, tempObj2); list.set(n+1, tempObj1); System.out.println(tempObj1.y +" "+ tempObj2.y); } } } if(flag==false) { this.object=list; } }
Il problema è che l'if (tempObj1>=tempObj2) lo esegue solo una volta come se non tenesse conto dei cambi di
PS object è la LinkedList che andrà a modificare