Difference between revisions of "User talk:Awesomeness"
(response, minor cleanup on header) |
m (grammar correction) |
||
Line 23: | Line 23: | ||
} | } | ||
</pre> | </pre> | ||
− | Here I assume that you use ArrayList to store you bullets and your bullet classname is Bullet. If you use a plain array to keep the | + | Here I assume that you use ArrayList to store you bullets and your bullet's classname is Bullet. If you use a plain array to keep the bullets, consider change to ArrayList. It is more flexible. » <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> » 14:09, 2 May 2009 (UTC) |
---- | ---- |
Revision as of 15:09, 2 May 2009
- Archived talks:
- Archived Talk 20090502
Okay, I need to make a list of bullets. I have made a bullet class and everything, but I need a special list that will let me access all of the bullets in a while/for loop and be able to add and remove them at any time and never mess up. If I did this in a normal array I could do a for loop and access using an increasing number, but I wouldn't know when to stop. In a while loop, if I used while(bulletsArray[x] != null) and then increment x, after I remove my first bullet that say, hit a wall, it will stop there. I need help!
- Thanks,
- Awesomeness 14:02, 2 May 2009 (UTC)
I think this will do:
ArrayList<Bullet> bullets = new ArrayList<Bullet>(); for (int i = 0; i < bullets.size(); i++) { Bullet bullet = bullets.get(i); if (bullet.needRemove()) { // I think this will work // bullets.remove(i--); // but usually I do bullets.remove(bullet); i--; } }
Here I assume that you use ArrayList to store you bullets and your bullet's classname is Bullet. If you use a plain array to keep the bullets, consider change to ArrayList. It is more flexible. » Nat | Talk » 14:09, 2 May 2009 (UTC)