In the following provided code, on the press of key "k" an animation should take place before spawning the magic attack, but unless i use something like greenfoot delay, only the last frame is shown, no matter how much time i put between the frames to explain the code, I have 4 pictures that it should cycle thru with 5 acts cooldown between each of them, thats why the "i" in the for goes to 19. From 1 to 2, 5 acts, 2 to 3, 5 acts and 3 to 4, 5 acts, summed with the 4 acts needed to do the animation, its 19. Please help i dont know what else to do :(((
if (Greenfoot.isKeyDown("k") && !kKeyPressed && Mana.mana >= 10&& magicCooldown==0) {
kKeyPressed = true;
imageToggleCooldown=0;
for (int i = 0; i < 19; i++) {
cycleImagesMagic();
}
Mana.instance.lmana(10);
magicCooldown=200;
spawnMagicAttack();
}
if (!Greenfoot.isKeyDown("k")) {
kKeyPressed = false;
}
}
private void cycleImagesMagic() {
if (imageToggleCooldown == 0) {
setImage("magic/MagicAttack" + magicAttack + ".png");
magicAttack = (magicAttack + 1) % 4;
imageToggleCooldown = 5; // Adjust the cooldown as needed
} else {
imageToggleCooldown--;
}
}
