Legacy GM Bullet delay

yvodlyn

Member
Hello everyone,
I'm trying to make a bullet delay. It works but the sprite to shoot appears and disappears very quickly. I would like for the sprite to shoot to stays. Can someone tell me what wrong on my code?

here the code:

Create Event:

global.Php = 6;
speed_x = 0;
speed_y = 0;
grav = 0.3;
cooldown = -1;

Step Event for player config:

var spd_wanted = 0; //The wanted horizontal speed for this step

if(key_left)
{
spd_wanted -= 4;
}
if(key_right)
{
spd_wanted += 4;
}

speed_x += (spd_wanted - speed_x) * 0.1; //Smoothly accelerate / decelerate to the wanted speed.

var xsp = round(speed_x); //Turn the theoretical value into an integer for collision and movement

Step Event for player animation:


if (key_right || key_left) {
image_speed = .2;
sprite_index = spr_player_run;
} else {
image_speed = .3;
sprite_index = spr_player_idle;
}

//Sprite direction
if (xprevious < x) {
image_xscale = 1;
} else if (xprevious > x) {
image_xscale = -1;
}
Step Event for shooting:

cooldown--
///Shooting
if (keyboard_check(ord('X')) && cooldown < 0) {
if (sprite_index == spr_player_idle or sprite_index == spr_player_jump or sprite_index == spr_player_run){
speed_x = 0;
var len = sign(image_xscale)*2;
//Create bullet
instance_create(x + lengthdir_x(len, image_angle), y + lengthdir_y(len, image_angle), obj_bullet);
sprite_index = spr_player_shoot;
}
cooldown += room_speed/2;
}
 
Last edited:
There must be some more code that you haven't posted, because I don't see where you are changing your player sprite (apart from setting it to spr_player_shoot).

Post the rest of the code for obj_player, particulary any code that modifies sprite_index.

I think you will find you have some code that is setting sprite_index, such that it replaces the spr_player_shoot immediately after you shoot, and you will need some sort of timer to prevent that from happening for a second or two when the player shoots.
 
W

Wadlo

Guest
I agree with IndianaBones. Your code actually looks like it is working. Because there is only one call that changes the sprite_index, it is being changed somewhere else. Somewhere else you probably have code that moves the character if certain keys are pressed. That is where you need to add a boolean such as isShooting.

Code:
if (keyboard_check(vk_left) {
    if isShooting == false {
        speed_x = -1;
        sprite_index = spr_player_run;
    }
}
Hope this helps. Good luck
 
M

Matt Hawkins

Guest
I'd try something like -
Code:
if cooldown > 0
    {
    image_index = spr_player_shoot;
    }
 
Top