This animation code draws a specific animation frame depending on which y coordinate the monster is on.
My bulky animation code was condensed into the code below by a forum user on the gamedev forum.
I never understood why the break statement is needed. I decided to comment the break statement out and notice it will only draw the last animation frame. If I have the break statement, it will instead animate all frames.
I know a break statement breaks out of the closest loop it is close to. But it does not give me an insight on why the break statement is needed had I not run the code experimentally.
// animating the image frames of the ghost
for(int i = 0; i < 3;i++)
if(position.getY() < positionLimits[i])
g.drawImage(ghostMovementAnimation.get(i), (int)position.getX(), (int)position.getY(), null);
Edited by warnexus, 24 May 2013 - 08:03 PM.