java - How to remove Sprite/Object from ArrayList? -
this question exact duplicate of:
- removing sprite when touched 1 answer
i created arraylist sprites needs removed, when sprites touched added arraylist.
//drawing enemy spawns , making them move public void draw(spritebatch batch){ for(sprite drawenemy:enemies) { drawenemy.draw(batch); drawenemy.translatey(deltatime * movement); touchinput(drawenemy.getx(),drawenemy.getwidth(),drawenemy);//2nd method } } public void touchinput(float x,float w,sprite sprite){ float touchx=gdx.input.getx(); if(gdx.input.justtouched()){ if(touchx > x && touchx < x+w ){ removeene.add(sprite);// adding current sprite array list when touched } //removeene arraylist } }
iterator<sprite> = removeene.iterator(); while (it.hasnext()) { it.remove(); }
Comments
Post a Comment