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

SOLVED How to make text temporarily appear after damaging an enemy?

MoriMori

Member
For my game, I wish to have it so when you hit the enemy with a bullet, a text temporarily appears saying
"-1" I have created an obj for this text aswell with a sprite assigned and just after it hit the enemy I want it to say "-1" and disappear really quickly

Any ideas on how to do this?
 

FrostyCat

Redemption Seeker
It makes no sense for anyone who knows how to do a bullet to not know how to do a pop-up score. The two are done with near-identical technique --- with a bullet you set the created instance's direction and speed, with a pop-up score you set the number it displays.

obj_score_popup Create event:
GML:
amount = 0;
colour = c_black;
alarm[0] = room_speed;
obj_score_popup Alarm 0 event:
GML:
instance_destroy();
obj_score_popup Draw event:
GML:
draw_set_font(fnt_score);
draw_set_colour(colour);
draw_text(x, y, string(amount));
Triggering a score popup:
GML:
with (instance_create_depth(x, y-48, depth-1, obj_score_popup)) {
    amount = -1;
    colour = c_red;
}
 

lost

Member
My first solution modifies the thing that is hit, not the bullet.

GML:
////In Create:

show_damage_duration = 0.5;  // seconds
show_damage_expired = show_damage_duration; // seconds
show_damage = false;
text_yoffset = 10;

////In Collision:

show_damage_amount = your_damage;
show_damage_expired = 0.0;

////In Step:

show_damage= ( show_damage_expired < show_damage_duration );
if ( show_damage ) damage_expired += 1.0/room_speed;

////In Draw:
draw_sprite_ext( ... )
if ( show_damage_expired < show_damage_duration ) {
  var show_damage_alpha = 1.0 - (show_damage_expired/show_damage_duration);
  draw_text_color(x,y-text_yoffset, string_format(show_damage_amount,1,0), c_red, c_red, c_red, c_red, show_damage_alpha );
}


Here is another solution, that involves creating a new object that is placed on a special layer:

Create an object called o_Damage_Show:

GML:
////In Create:

duration = 1.0;  // seconds
expired = 0.0;
text= "Hurt!";
alpha = 0.0;
color = c_red;

////In Step:

expired += 1.0/room_speed;
if ( expired > duration ) instance_destroy();
alpha = sin( expired/duration * 3.14159 );   // ramps up and down
y-=1;  // "floats up"

////In Draw:

draw_text_color(x,y, text, color, color, color, color, alpha );
When the bullet collides, create the o_Damage_Show object at the position of the collision, on the layer desired. Make sure to set the new object's text string to the desired damage amount.

GML:
new_id = instance_create_layer( hitx, hity, "Messages", o_Damage_Show );
new_id.text = "Man that's a lot of damage!";
 
Last edited:
Top