recursion - Why does object not delete itself but continue rendering (Java) -


the question have why recursive laser beam, speak, rendering kind of trail. idea behind class create laser making multiple copies of itself, , each time checking whether or not has reached end of screen or had hit object. supposed delete once update cycle rolls around, , since update called before render, should delete leaving smooth laser. laser leaving trail when moving it, not smooth if parts of previous update still there , not removed. included images when paddle still(what it's supposed like), when paddle moving(the laser leaving trail.) included handler class updates first, renders, pointer class.

pictures:

how supposed (paddle still)

https://i.stack.imgur.com/jeqdy.png

how looks (paddle moving)

https://i.stack.imgur.com/4twx3.jpg

pointer class:

public class pointer extends gameobject{      private gameobject p1, p2;     private handler handler;     private boolean more;      public pointer(int x, int y, id id, handler handler) {         super(x, y, id);         p1 = handler.object.get(0);         p2 = handler.object.get(1);         this.handler = handler;          if(id == id.beam1){             if(getbounds().intersects(p2.getbounds()) || x > game.width){                 return;             }             else {                 handler.addobject(new pointer(x +10, y, id, handler));             }         }       }      public void update() {         handler.removeobject(this);     }      public void render(graphics g) {         g.setcolor(color.red);         g.fillrect(x, y, 5, 5);      }      public rectangle getbounds() {         return new rectangle(x,y,5,5);     } } 

handler class:

public class handler {      arraylist<gameobject> object = new arraylist<gameobject>();      public void update(){         for(int = 0; < object.size(); ++){             object.get(i).update();         }     }     public void render(graphics g){         for(int = 0; < object.size(); ++){             object.get(i).render(g);         }     }     public void addobject(gameobject object){         this.object.add(object);     }     public void removeobject(gameobject object){         this.object.remove(object); } 


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -