You can just add a new variable and not mess with what you have.
cooldown1_timer = 100; for example.
when cooldown1 is true, cooldown1_timer counts down (or up, whichever). When it hits 0, it sets cooldown1 to false.
Remember to reset the timer before you set cooldown1 to true
This is what I've got right now:
create event:
image_speed = 0; //we dont want the image playing on its own (we dont use image_index here, but you might)
cooldown1_timer = 100; // represents 100% cool down needed
cooldown1_speed = 1; // don't use a number like 3, 3 is not evenly divisible by 100, 2.5 is good. 1.1 is good.
cooldown2_timer = 100; // represents 100% cool down needed
cooldown2_speed = 1; // don't use a number like 3, 3 is not evenly divisible by 100, 2.5 is good. 1.1 is good.
cooldown3_timer = 100; // represents 100% cool down needed
cooldown3_speed = 1; // don't use a number like 3, 3 is not evenly divisible by 100, 2.5 is good. 1.1 is good.
cooldown4_timer = 100; // represents 100% cool down needed
cooldown4_speed = 1; // don't use a number like 3, 3 is not evenly divisible by 100, 2.5 is good. 1.1 is good.
draw event:
// in the draw event after everything else is drawn
if (cooldown1 != 0) // if we arent cooled down
{
draw_sprite(spellcooldown,global.spell[global.spellslot1,8]/(100/4),
view_xview[0]+28,view_yview[0]+250)
cooldown1_timer -= cooldown1_speed; //if you have 20 images, (100/image_number) will be 5. Divide cooldown1 by 5 and get the image number
// 100 / 5 = 20 for example
};
if (cooldown2 != 0) // if we arent cooled down
{
draw_sprite(spellcooldown,global.spell[global.spellslot2,8]/(100/4),
view_xview[0]+28,view_yview[0]+250)
cooldown2_timer -= cooldown2_speed; //if you have 20 images, (100/image_number) will be 5. Divide cooldown1 by 5 and get the image number
// 100 / 5 = 20 for example
};
if (cooldown3 != 0) // if we arent cooled down
{
draw_sprite(spellcooldown,global.spell[global.spellslot3,8]/(100/4),
view_xview[0]+28,view_yview[0]+250)
cooldown3_timer -= cooldown3_speed; //if you have 20 images, (100/image_number) will be 5. Divide cooldown1 by 5 and get the image number
// 100 / 5 = 20 for example
};
if (cooldown4 != 0) // if we arent cooled down
{
draw_sprite(spellcooldown,global.spell[global.spellslot4,8]/(100/4),
view_xview[0]+28,view_yview[0]+250)
cooldown4_timer -= cooldown4_speed; //if you have 20 images, (100/image_number) will be 5. Divide cooldown1 by 5 and get the image number
// 100 / 5 = 20 for example
};
It's still not working properly. Currently, it's not drawing the new sprite.
Edit- It is now drawing the sprite, but it's not animating it. It stays at the first image index, then disappears at the correct time.
After looking at the code again, should I adjust the cooldown1_speed to match the timer? global.spell[global.spellslot1,8] is the cooldown in the array. So should I make a step event that says cooldown1_speed = global.spell[spellslot1,8] ?
Edit - I'm making progress. It's now slightly animated, but It's not starting the cooldown image from the beginning. It uses the image, then subtracts the frames that wouldn't show. IE - If the cooldown timer isn't 100, it doesn't show all of the sprite. It starts the sprite in the middle, then counts down.
Edit, actually, I don't know what it's doing. Even with the cooldown set to 100, it just starts the animation half way, then doesn't animate it. 50 works semi.
Edited by Criminon, 30 April 2012 - 03:34 AM.