Text Shadow

SP1D3R

Member
GM Version: All
Target Platform: Windows, but probably all
Download: see text below
Links: na

Maybe some people can use this little script i created last night.
It will transform your text with a simple shadow effect.
Save this script as draw_text_shadow
Code:
/// draw_text_shadow(x, y, string, font, shadow_size, shadow_colour, text_colour);
var _x, _y, _string, _font, _shadow_size, shadow_colour, text_colour;
_x = argument[0];
_y = argument[1];
_string = argument[2];
_font = argument[3];
_shadow_size = argument[4];
_shadow_colour = argument[5];
_text_colour = argument[6];
draw_set_font(_font);
draw_set_colour(_shadow_colour);
draw_text((_x + _shadow_size), (_y + _shadow_size), string(_string));
draw_set_colour(_text_colour);
draw_text(_x, _y, string(_string));
GMS 2.3:
Code:
/// @description Adds a shadow to text.
/// @function draw_text_shadow(x, y, string, font, shadow_size, shadow_colour, text_colour);
/// @param x
/// @param y
/// @param string
/// @param font
/// @param shadow_size
/// @param shadow_color
/// @param text_color
function draw_text_shadow(){
    var _x, _y, _string, _font, _shadow_size, _shadow_colour, _text_colour;
    _x = argument[0];
    _y = argument[1];
    _string = argument[2];
    _font = argument[3];
    _shadow_size = argument[4];
    _shadow_colour = argument[5];
    _text_colour = argument[6];
    draw_set_font(_font);
    draw_set_colour(_shadow_colour);
    draw_text((_x + _shadow_size), (_y + _shadow_size), string(_string));
    draw_set_colour(_text_colour);
    draw_text(_x, _y, string(_string));
}
Have fun with it!
 
Last edited:
Hi SP1D3R,

Thanks for your script! It got me thinking and I added another "Text Soft Shadow Version" (kinda sorta similar to photoshop drop shadows).
Play with parameters shadow_blurriness and shadow_strenght to adjust the looks based on your font.
Warning: Uses alot more draws to get the soft look.
Use at your own risk.




Code:
/// @function draw_text_softshadow
/// @param x_position
/// @param y_position
/// @param text
/// @param font_name
/// @param text_colour
/// @param shadow_colour
/// @param shadow_offset_x
/// @param shadow_offset_y
/// @param shadow_blurriness (higher numbers will be slower!)
/// @param shadow_strenght of shadow, (0.01=soft, 1=strong);
/// example: draw_text_softshadow(10,10,"Hello World!", font_name, c_white, c_black, 0,5,6,0.01, );

var _x, _y, _string, _font, _offset_x, _offset_y, _blurfactor, _shadow_colour, _shadow_strenght, _text_colour, ix, iy;
_x = argument0;
_y = argument1;
_string = argument2;
_font = argument3;
_text_colour = argument4;
_shadow_colour = argument5;
_offset_x = argument6;
_offset_y = argument7;
_blurfactor = argument8;
_shadow_strenght = argument9;

draw_set_font(_font);
var shadow_strenght_calc = _shadow_strenght/(_blurfactor * _blurfactor)
draw_set_alpha(shadow_strenght_calc);
draw_set_colour(_shadow_colour);
//draw_text((_x + _offset_x), (_y + _offset_x), string(_string));
var bx = _blurfactor/2;
var by = _blurfactor/2;

for (ix = 0; ix < _blurfactor; ix++) {
    for (iy = 0; iy < _blurfactor; iy++) {
        draw_text((_x-bx) +_offset_x + ix, (_y-by) +_offset_y + iy, string(_string));
    }
}
draw_set_alpha(1);
draw_set_colour(_text_colour);
draw_text(_x, _y, string(_string));
 

Attachments

Last edited:

skofrant

Member
I have a question for this post

is there any script that i can use these values along with the shadow?

GML:
draw_text_transformed_colour(x, y, string, xscale, yscale, angle, c1, c2, c3, c4, alpha);
Thank You
 
Top