I have a batch of sprites (textured OpenGL ES 2.0 Quads) which I loop through to move. Here is a simplified version of my code:
//'sprite' & other values have been are assumed to exist for the purpose of the question
public void moveQuadBatch(){
//Loop for as many sprites as there are to draw
for (loop = 0; loop < sprite.number; loop++){
moveQuadNumber(loop); //this method will move the sprite that corresponds to the number loops so we can move through the entire batch and move each individual sprite
}
}
Now, for some batches, there is a countdown timer, or some other condition (and there isn't for others, like above). Therefore, I've created a similar method for these objects like so:
public void moveQuadBatchWithCheck(){
//Loop for as many sprites as there are to draw
for (loop = 0; loop < sprite.number; loop++){
//Only do this if the particular sprite's countdown/delay counter has reached 0 (counting down from another method not seen here)
if (sprite.delay[loop]<0){
moveQuadNumber(loop); //this method will move the sprite that corresponds to the number loops so we can move through the entire batch and move each individual sprite
}
}
}
However, I'm not entirely happy about this as there is a lot of code duplication. Instead of having these 2 methods is there any way I can use the first one and somehow 'slipstream' the additional check into the for loop? Or otherwise cut down on the duplication that I have here? This is a simple example, there are others and currently I have multiple methods which are all very similar.
Edit
As mentioned, the above is somewhat simplified. I could have some for loops which check another value (other than delay for example), and some could check 2 conditions.