teaowl

DrawingHierarchyHack

Oct 7th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1.     /** меняет местами персонажа, и ближайший объект, для имитации глубины */
  2.     public void drawingHierarchySorter() {
  3.         List<Entity> list = getEntities();
  4.         // цикл по всем сущностям в мире
  5.         for (int i = 0; i < list.size() - 1; i++) {
  6.             Entity other_entity = list.get(i);
  7.             try {
  8.                 /*
  9.                  * если по вертикали сущность выше персонажа,
  10.                  * но её индекс меньше, (т.е. она отрисовывается первой)
  11.                  * то они с персонажем меняются индексами в списке
  12.                  **/
  13.                 if (other_entity.y > twilie.y) {
  14.                     if (i < list.indexOf(twilie)) {
  15.                         list.remove(list.indexOf(twilie));
  16.                         list.add(list.indexOf(other_entity), twilie);
  17.                     }
  18.                     //то же самое и в обратном случае
  19.                 } else if (list.indexOf(twilie) < i) {
  20.                     list.remove(i);
  21.                     list.add(list.indexOf(twilie), other_entity);
  22.                 }
  23.             } catch (IndexOutOfBoundsException ex) {
  24.                 System.out.println("индексы барахлят: " + ex);
  25.             }
  26.         }
  27.     }
Add Comment
Please, Sign In to add comment