• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Game runs extremely slow

NimNom1234

Member
Hi.
I'm having a problem in my game. If i spam the attack button, the game slows down to fractions of 1 fps.

Help?

Thanks :)
 

NimNom1234

Member
instance_create(global.playx, global.playy, obj_char_sword_hitbox)
if global.key_sword = true {
swinging = true
if global.direct = 0 {
sprite_index = spr_char_hitbox_down
alarm[4] = 6.6
}
if global.direct = 1 {
sprite_index = spr_char_hitbox_right
alarm[4] = 6.6
}
if global.direct = 2 {
sprite_index = spr_char_hitbox_up
alarm[4] = 6.6
}
if global.direct = 3 {
sprite_index = spr_char_hitbox_left
alarm[4] = 6.6
}
}
if swinging = false{
instance_destroy()
}



This is the code inside of the swords collision box. key_sword equates to pressing the attack button and swinging is the state of swinging the sword. Lemme know if more is needed :)
 

NimNom1234

Member
I didnt think I was, but I might be. The hitbox is created and deleted once every frame. Its being ran in a step event.
 
T

TimothyAllen

Guest
Creating that many instance isn't a good idea... even if they only exist for a few frames. That's a lot of memory allocation and GC.

Edit: that will destroy the calling instance... not the hitbox.
 

TheouAegis

Member
Don't create hitbox objects. Just change the mask_index for the player, do collision tests for the weapon damage, then reset the mask_index.
 
Top