• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Trouble with draw_sprite_ext - HELP!

S

somebenishguy

Guest
currently working on my first ever game project. I am having trouble getting draw_sprite_ext to work. forgive me if I make any mistakes in the process of asking for help, I apologize, and will gladly supply any needed information.

anyway, the problem I'm having is that I am trying to implement a red flash when the player or an enemy takes damage. it works for the player, and one enemy, but the second enemy i've tried to add it to doesn't seem to work. the red flash displays the enemy's default sprite, even when the enemy is performing an animation. I had this problem with the other enemy originally, but I forget how I fixed it. any advice would be greatly appreciated, as I have been trying to fix this for hours before deciding to ask on the forums. here is the code for the draw tab in the nonfunctional and functional enemy respectively:



disfunctional:


draw_self();

//damage flash going right
if (flash > 0) && (hp > 0) && (hsp >= 0)
{
flash--;
if (image_index = sTwid)
{
draw_sprite_ext(sTwid,image_index,x,y,1,1,image_angle,c_red,1);
} else if (image_index = sTwidF)
{
draw_sprite_ext(sTwidF,image_index,x,y,1,1,image_angle,c_red,1);
} else if (image_index = sTwidF2)
{
draw_sprite_ext(sTwidF2,image_index,x,y,1,1,image_angle,c_red,1);
}
}



functional:


draw_self();

//damage flash going right
if (flash > 0) && (hp > 0) && (hsp >= 0)
{
flash--;
draw_sprite_ext(sStenchman,image_index,x,y,1,1,image_angle,c_red,1);
}

//damage flash going left
if (flash > 0) && (hp > 0) && (hsp < 0)
{
flash--;
draw_sprite_ext(sStenchman,image_index,x,y,-1,1,image_angle,c_red,1);
}
 
You probably need to be checking the sprite_index not the image_index in your if statements. The image_index is the frame of the sprite that is currently active, not the sprite resource that is being used by the object.
 
S

somebenishguy

Guest
Thanks so much for the help! I feel silly for getting stuck on such a seemingly small issue. Although it is odd that the others didn't require an if statement.

anyway, I'm glad to have this resolved. thanks for the quick reply
 
To be honest, I wouldn't even bother using draw_sprite_ext if all you are doing is changing the current sprite to be red.
I would probably change your entire draw code to just do something like the following:
Code:
//damage flash going right
if (flash > 0) && (hp > 0) && (hsp >= 0)
{
  flash--;
  draw_set_colour(c_red);
  draw_self();
  draw_set_colour(c_white);
}
What that does is change the drawing colour to be red immediately before drawing the current sprite, draws it in red with draw_self() and then changes the drawing colour back to white (the default).

I'm pretty sure that is what I have done with my damage indicating in my game, and it means you are not having to check what sprite is assigned or having to call draw_sprite_ext for each sprite you might have set the object instance to use.
 
Top