shoot per 10 frames instead of each frame

N

NeoIdea

Guest
Hello!
I am wanting to find a way to shoot with 'Mouse Left Button action' rather than with the 'Left Button Pressed' action, as I'd rather not have to click a bunch of times.
With 'Mouse Left Button action' it seems that it fires each frame. I would like to fire say.. every 3 frames instead and keep the speed of each bullet instance.
Here's the code just in case it helps. It's a project that is a deviation of the Asteroids Shaun Spalding tut series.
And thank you for all the amazing tutorials, if you happen to see this!


bullet = instance_create(x, y, obj_bullet);
bullet.direction = image_angle;
bullet.image_angle = image_angle;
bullet.speed = 10



Thanks!
 
A

ajan-ko

Guest
Event Create
Code:
weapon_delay=0;
Your Code
Code:
weapon_delay-- //weapon delay minus 1
if weapon_delay<0 {
   bullet = instance_create(x, y, obj_bullet);
   bullet.direction = image_angle;
   bullet.image_angle = image_angle;
   bullet.speed = 10
   weapon_delay=3; //3 frames delay
}
 
N

NeoIdea

Guest
ok thats awesome. Its funny i did it with alarms just now. Guess i had a brain fart.
With Global Left Button
alarm[4] += 2;

in the Step Event I put

if (alarm[4] > 10){
bullet = instance_create(x, y, obj_bullet);

bullet.direction = image_angle;
bullet.image_angle = image_angle;
bullet.speed = 10
audio_play_sound(snd_shoot, 0, 0);
alarm[4] -=10 ;
}

Sorry about the poor formatting, this is my first post.
Thanks a lot for your fast response, I will do it your way.
 
N

NeoIdea

Guest
Cool. :)

Yep, there are a few ways of doing this. So, there is no real right or wrong way. Just go with the one that you understand the best :)
Well I really do appreciate y'alls help with this. I learned something from both of you that I can apply to the rest of my game and future games.
Cheers!!!
 
Top