Java Syntax Explantion for attached snippet, ArrayList Enumeration -
i next through kilobolt tutorial on game dev , next code appears
arraylist projectiles = robot.getprojectiles(); (int = 0; < projectiles.size(); i++) { projectile p = (projectile) projectiles.get(i); if (p.isvisible() == true) { p.update(); } else { projectiles.remove(i); } i struggling on how line hangs together
projectile p = (projectile) projectiles.get(i); projectile p creating new projectile called p projectile class here?
(projectile) projectiles.get(i); this? i'm not sure why (projectile) getting projectile arraylist element? bracketed section indicating?
to reply specific questions:
he's creating reference specific, existing projectile returned robot.getprojectiels()
he's getting specific projectile index array backed list (arraylist). since he's not using generics, has cast projectile object.
however...this code looks quite out of date.
hard tell end goal here. if you're looking phone call update on "visible" projectiles , end list has visible projectiles, construction code such:
list<projectile> visibleprojectiles = new arraylist<projectile>(); (projectile p : robot.getprojectiles()) { if (p.isvisible()) { p.update(); visibleprojectiles.add(p); } } note:
the utilize of generics the utilize of java-style foreach thatp.isvisible() == true unnecessarily verbose. java syntax
No comments:
Post a Comment