Level UP popup text

Z

zakblue

Guest
Hi Guys,

I'm farly new to GM2 and i'm making an RPG with a basic levelling system.

I have followed a youtube guide to have my character level up and all i would like is to have 3 seconds
of text popping up everytime my character levels up. I have had various struggles with this trying to get it to work without it affecting all the rest of the text on the screen, and then not just be persistent after showing.

The biggest difficulty i have is being able to trigger the popup, as if I add a key press event to 'trigger' the level up, I can cause the text popup.

I am controlling the levelling and stats in my player object.
I have tried creating a separate object for the popup text but i get much the same results as leaving it in the player object. 'ding' being the variable i would like as the trigger for the levelup text.

I will paste the code that i'm using (unnecessary extra fat like movment controls trimmed)


Create:

event_inherited(); //from enemy object parent I have setup
hp = 3;
spd = 2;
hspd = 0;
vspd = 0;
xaxis = 0;
yaxis = 0;
len = 0;
dir = 0;
image_speed = 0;
scr_get_input();
state = scr_move_state;
face = 0;
ding = false;
weapon_sprite = noone;
// Level up text
alarm[1] =room_speed * 3;
text_alpha = 1;

Step:

// Move the player in the step event
depth = -y;
script_execute(state);
sprite_index = sprite[face, movement];
// Check for death
if (obj_player_stats.hp <= 0) {
instance_destroy();
game_restart();
}
//Levelup
if (text_alpha > 0)
text_alpha -= 0.01;

Alarm 1:
ding=false;

Collision with experience object (that spawns after enemy killed) :

with (other) {
instance_destroy();
}
// Level up code
with (obj_player_stats) {
expr += 1;
if (expr >= maxexpr) {
level += 1;
expr = expr-maxexpr;
maxexpr *= 2;
hp += 2;
maxhp += 2;
stamina += 2;
maxstamina += 2;
attack += 1;
ding = true; // I thought I could use this variable changing to true to trigger the levelup txt
audio_play_sound(snd_levelup,0,false);
}
}
//most of the above ^^ variables have been set separately in obj_player_stats

Draw:

//Draw Player Shadow
draw_sprite(spr_player_shadow, image_index, x, y,);
draw_self();

if (ding) {
draw_set_colour(c_black);
draw_set_alpha(0.60);
draw_set_font(fnt_IG);
draw_set_color(c_white);
draw_text(x,y, "LevelUP");
draw_set_alpha(1);
}

KEY PRESS F1:
ding=true; //to test what happens here, and actually shows up 'LevelUP' in the correct place and disappearing after 3 seconds as required. This only works once though and then doesn't appear again on another press.

When my character actually levels up I don't get the 'LevelUP' on the screen, just the increase in stats.

I hope this makes sense, sorry I am fairly new to GM2 and stumped by this one.
Any help would be much appreciated!
 
Looks alright, just make sure when you set ding to true, also set the alarm[1] and text_alpha (if you end up using that variable instead of .60).
For example, right after the "ding = true" line in your F1 press event and in your Collision with experience object, put:
Code:
alarm[1] = room_speed*3;
text_alpha = 1;
This will make sure to reset ding to false 3 seconds later. Right now, you only have the alarm being set in the create event, so once you set ding to true, it will stay true forever unless you reset the alarm. :)

And in your draw event, instead of "draw_set_alpha(.60);", put:
Code:
draw_set_alpha(text_alpha);
 
Z

zakblue

Guest
Looks alright, just make sure when you set ding to true, also set the alarm[1] and text_alpha (if you end up using that variable instead of .60).
For example, right after the "ding = true" line in your F1 press event and in your Collision with experience object, put:
Code:
alarm[1] = room_speed*3;
text_alpha = 1;
This will make sure to reset ding to false 3 seconds later. Right now, you only have the alarm being set in the create event, so once you set ding to true, it will stay true forever unless you reset the alarm. :)

And in your draw event, instead of "draw_set_alpha(.60);", put:
Code:
draw_set_alpha(text_alpha);
Thanks for that. I have now added those changes and with the F1 key press the text appears and fades nicely whilst being repeatable.

I still don't get the 'LevelUP' text appearing when actually levelling up though.
 

Roderick

Member
This may make things more difficult for you right now, but might make things easier in the future:

Make a particle system that generates particles that move straight up and fade out over a second or two.

Create a script that accepts the following arguments: X and Y coordinates, a string, and a color.
When the script is called, make your particle system generate particles of the chosen color, then run a loop that changes the particle's texture to each letter in the string and then generates it at the X,Y coordinate, shifted left or right based on its position in the string.

Once the system is set up, if the player takes damage, call the script with the player's location, the amount of damage taken (converted to a string!), and the color red. An enemy heals itself? Enemy location, amount of damage healed and green. Player levels? Player location, "Level UP!" and yellow.
And since it's a particle (or rather, a group of particles), you don't need to do any manipulation of them to move or delete them; it will handle that all by itself.
 
Particle idea is good because it has less overhead than anything else really, but I generally just create an object called obj_info_text or something, add str = "" into it's Create Event, setup the text how I want in the Draw Event and draw the str variable at it's x/y, set either a timer or alternatively just fade the alpha in the Step Event as well as decreasing it's y (to make it float up) and when the timer pops/alpha <= 0 destroy the instance. Unless I'm doing thousands of popups constantly it doesn't impact performance. And it's easy enough to just store the instance id when I create a popup and change the str variable for that instance. Not high-tech or super performant, but simple, quick and easy to setup. Then I can get on with the business of making mah game.
 
Thanks for that. I have now added those changes and with the F1 key press the text appears and fades nicely whilst being repeatable.

I still don't get the 'LevelUP' text appearing when actually leveling up though.
That's because you're actually setting all those variables (including ding) inside the stats object, and not the player. If you're trying to set the player object's variables from within a with statement, use the keyword other or the instance id of the player.
Like this:
Code:
with (obj_player_stats) {
expr += 1;
if (expr >= maxexpr) {
level += 1;
expr = expr-maxexpr;
maxexpr *= 2;
hp += 2;
maxhp += 2;
stamina += 2;
maxstamina += 2;
attack += 1;
other.ding = true; // I thought I could use this variable changing to true to trigger the levelup txt
other.alarm[1]=3*60;
other.text_alpha=1;
audio_play_sound(snd_levelup,0,false);
}
If that doesn't work, try putting the player object name instead of "other."

Also, I agree with the other guys to make either a particle or object that has customizable text & color so it's more versatile.
 
T

Taddio

Guest
@Roderick
I've been trying to do something like that for a while! Do you simply use a particle sprite with 0-9 + A-Z subimages?
What would your loop look like to convert all string letters to corresponding sprite?
Really interested in that system!
 
Last edited by a moderator:
Z

zakblue

Guest
Thanks for all your help, I got it the LevelUP text to work for now. I'll take some time to set up a particle system for future use too. Cheers
 

Roderick

Member
@Roderick
I've been trying to do something like that for a while! Do you simply use a particle sprite with 0-9 + A-Z subimages?
I actually haven't used GMS in a long time; most of my advice has to be taken as theory and pseudo-code, because I don't remember how things work here.
Also, my experience is with with 1.4; some things have changed since then.

When you create a particle system, you set all of its properties. Those properties aren't set in stone. I was using a sprite particle, and changing the texture before emitting the particle.

What would your loop look like to convert all string letters to corresponding sprite?
Really interested in that system!
First, use a fixed font (ie, all characters are the same width).

Code:
var char_width = 8; //whatever the width of the characters is
var start_pos = -round(string_length(popup_string) * char_width / 2); //Length of string in characters, times pixel width, halved and made negative gives the x offset of the first character.

for (var i = 0; i < string_length(popup_string); i++)
{
var character = string_char_at(popup_string, i);
create_particle(x + start_pos + i * char width, y, character); // this is your custom script that makes the particle
}
You could use a ds_map to store the textures with the characters passed to your script.
You could also use an if statement to check if the character exists in that ds_map, and only try to create the particle if it does, skipping to the next otherwise.
 
Last edited:
Top