In Main class i make the ArrayList variable "b" thats referring to a seperate class called "Bullets"
ArrayList<Bullets>b = new ArrayList<Bullets>();
This is from the Update() method.
if(S==1) {
Bullets add = p1.getBull();
add.xVel = 3;
b.add(add);
S++;
}
In the Update() method. Can you please explain in detail what the .get and .add are all about in association with the loop. Iv searched EVERYWHERE to find information but cant wrap my head around it.
for(int x = 0; x<b.size(); x++) {
b.get(x).move();
if(b.get(x).rect.intersects(p1.rect)&&b.get(x).xVel<0) {
p1.health--; //Decrease players health once hit
b.remove(x); //Once bullet hit player, remove bullet from screen
x--;
continue;
}
Questions:
In " b.get(x).move(); " is the (x) referring to an element in the array or an x variable in my Bullets.move() method?
In " b.add(add); " I'd really like to know what its doing in relation with the whole if statement?
In " b.remove(x); " how does removing the (x) element from the array make the bullet disappear from the screen?
Answers would be EXTREMELY appreciated !

New Topic/Question
Reply



MultiQuote





|