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

draw_text using multiple colours ?

Amigo121

Member
Hello, I have made huge improvement with my very first game.

draw_text.png

However, I have encountered another "impossible problem". I am trying to draw recently gained score points for few seconds in different colour than is the original "Score:" text.
(the "global.kill_y" is static number, because i did not manage to make it in different colour)

GML:
draw_set_font(fMenu);
draw_set_colour(c_white);
draw_set_halign(fa_left);

draw_text(16,48,"Score: " + string(global.points)+ global.kill_y);

if (global.kill_points = true)
{
    draw_set_color(c_yellow);
    draw_text(16,96,"+100");
}
I technically managed to do that (that yellow +100 under the Score, which disappears after few seconds), but coud not make it in the same draw_text function as the score is.
I could draw it manually next to it, but it might cause problems later. I can not pass variable with more arguments (like colour).

Do you have any ideas?
Thanks for all comments, I really appreciate it.
P.S.: I have tried looking for help on YouTube and other forums before I decided to make this post.
 

curato

Member
You might want to make a variable for the text color of the score then set it yellow for example then set an alarm to change it back to the white later.
 
L

LunaNightshade

Guest
I just looked into the existing draw_text functions and ... you can't change the color mid-string. You really have to do it with a separate call as you did.
As putting it next to it - there shouldn't be a problem with that. You just have to account for the x-value with the string_width of your current score.

See: https://docs2.yoyogames.com/index.h...e/instances/instance_variables/direction.html

That should probably get rid of any problems you might see with doing it in separate function calls.
 

Amigo121

Member
You might want to make a variable for the text color of the score then set it yellow for example then set an alarm to change it back to the white later.
Thanks for your idea, but I think the "Score: number" might get yellow too while changing the colour to yellow
 

Amigo121

Member
I just looked into the existing draw_text functions and ... you can't change the color mid-string. You really have to do it with a separate call as you did.
As putting it next to it - there shouldn't be a problem with that. You just have to account for the x-value with the string_width of your current score.

See: https://docs2.yoyogames.com/index.html?page=source/_build/3_scripting/4_gml_reference/instances/instance_variables/direction.html

That should probably get rid of any problems you might see with doing it in separate function calls.
Oh, that sounds interesting. I have no idea how I should use direction... could you make simple example?
Edit: Or provide some resource which might explain it little bit more?
 
L

LunaNightshade

Guest
Argh ... of course that is the wrong link.

GML:
draw_set_font(fMenu);
draw_set_colour(c_white);
draw_set_halign(fa_left);

var score_string = "Score: " + string(global.points);
draw_text(16,48,score_string);
if (global.kill_points == true) //Please use always == for comparison
{
    draw_set_color(c_yellow);
    draw_text(16+string_width(score_string),48," +100");
}
string_width() is supposed to give you the width of the string in pixels if used in draw_text()
 

Amigo121

Member
Argh ... of course that is the wrong link.

GML:
draw_set_font(fMenu);
draw_set_colour(c_white);
draw_set_halign(fa_left);

var score_string = "Score: " + string(global.points);
draw_text(16,48,score_string);
if (global.kill_points == true) //Please use always == for comparison
{
    draw_set_color(c_yellow);
    draw_text(16+string_width(score_string),48," +100");
}
string_width() is supposed to give you the width of the string in pixels if used in draw_text()
Thanks a lot!
 

curato

Member
Thanks for your idea, but I think the "Score: number" might get yellow too while changing the colour to yellow
Yes with that method you would have to seperate out the score text from the color and flip the color in between each.
 
Top