You're doing it wrong
No seriously, the example from davedes was pretty clear.
The update fonction is called at an interval which is not always the same, so for example is the first call is at 0ms, the second can be at 50ms, the third at 125ms, etc etc...
So each time you call the update the delta variable is here to give you the time in ms since the last execution, so you need to use that.
So what you need to do is store the time somewhere for example with your fonction and using davedes example, in your update method you need to do this :
Code:
MyClass extends BasedGameState{
int timeElapsed = 0;
public void update (..., int delta) {
timeElapsed += delta;
for(SpriteTower towerSprite: towersOnMap) {
if (towerSprite.getTower().speed <= timeElapsed) {
attack(towerSprite, npcs);
}
}
}
}
There you have it, you can put this code into a separate class which can be better but you would need to have the same mechanism and pass the delta variable as a parameter, it's the only way to have the correct timing.
Same way, to synchronize, you need to put your treatment in the update, and put some kind of boolean for example which will set the animation, like :
Code:
MyClass extends BasedGameState{
boolean isShooting;
public void update(...){
if (conditiontoshoot.isMet()){
... my treatment ...
isShooting = true;
}
if (myShot.isOver(){
isShooting = false;
}
}
public void render(...){
if (isShooting){
myAnimation.render(...)
}
}
}
Of course, again, you can have a more complex design, but ultimately, you still need to use the update/render method to synchronize everything.