• 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!

attack animation spawning non stop object as if holding down the button

S

Stratos.la

Guest
so i have an obj_ball which the plaer throws if i use it without the animation the ball goes smootly and nice (even though i still cant make it spawn from the second frame x,y of the attack animation) but when i add the animation the ball just endlesly keep flowing out of my character as if he is peeing! forgive me really but it seems like that! sorry again!
Code:
//attack
if (key_attack!=0) sprite_index = spr_player_attack; else sprite_index = spr_player_idle;
    with (instance_create_layer(x,y-20,"ball",obj_ball))
    {
        speed = 13
        gravity = 0.5
        image_angle = direction
        direction = obj_player1.image_angle + random_range(-1,1)
    }
and when i press "z" then i can catch a single frame of the attack animation happening but still the image is all messed up with a vast and rich amount of flooding balls!

GMS2 here!
 

PlayerOne

Member
You code looks fine, except that the instance_create_layer isn't tied to a key function in turn creating a bunch of objects instead. That's a guess from my glace at it. In any event I added a few extra brackets and moved some code around. See if it works.

Code:
//attack
if (key_attack!=0)
{
     sprite_index = spr_player_attack
     with (instance_create_layer(x,y-20,"ball",obj_ball))
     {
         speed = 13
         gravity = 0.5
         image_angle = direction
         direction = obj_player1.image_angle + random_range(-1,1)
     }
}
else 
{
sprite_index = spr_player_idle;
}
 
S

Stratos.la

Guest
wow just wow! you made my day! its like 00.30 here in Greece and i have work tomorow but i reaalyyy want to finish this game and you sir just made my night better and hopefully will have nice dreams! thank you! although i will ask one last thing if this is ok with you since i have 3 images for the attack animation running it 60fps just shows a blur. any idea how to fix that? im thinking it has something to do with sprite indexes?? but im still a beginner so im just trying out anything i can think of!
 

PlayerOne

Member
The animation should play out. If it's just the code you presented that is still giving you trouble try adjusting the image speed.

Code:
CREATE EVENT:
//1=normal speed, 0.5 = half normal image speed.
image_speed=0.5 <<< this adjusts the image speed of the object when a sprite plays by half the normal speed.
 
S

Stratos.la

Guest
when i put the image_speed under the sprite_index in the step event my sprite freezes and wont do any other animation after( as walking jumping etc)
wont the image_speed in the create event affect all sprites?? i have 6 frames for running , one for jumping and one for landing

Code:
//Animate
if (move!=0) image_xscale = move;
if (place_meeting(x,y+1,obj_ground))
{
    if (move!=0) sprite_index = spr_player_running; else sprite_index = spr_player_idle;
}
else
{
    if (vsp < 0) sprite_index = spr_player_jump; else sprite_index = spr_player_fall;
}
So it seems the last line of your code was freezing my sprite and would only try to play the attack animation. The else sprite_index = spr_player_idle I mean. Everything is smooth now except the attack animation. I'll look into it tomorrow! Thanks for your help friend!!
 
Last edited by a moderator:

PlayerOne

Member
By placing image_speed in the create event it will affect all sprites in that object when played out. If you want to use image_speed on a certain sprite when played you will need to reset the image speed to your desired speed at different point in your code.

Code:
//Animate
if (move!=0)
{
image_xscale = move;
image_speed=0.5
}
else
{
image_speed=1
}
  
if (place_meeting(x,y+1,obj_ground))
{
      if (move!=0){ sprite_index = spr_player_running}
      else{sprite_index = spr_player_idle;}
   }
   else
   {
      if (vsp < 0){sprite_index = spr_player_jump}
      else {sprite_index = spr_player_fall;}
   }
 
Top