font_enable_sdf

This function is used to enable or disable SDF Rendering for the given font. The font must have been added using font_add() and loaded from a font file - you cannot use SDF with sprite fonts or fonts that were added through the IDE.

Once SDF is enabled for a font, you can apply various effects to it.

NOTE This function cannot be used on HTML5, as HTML5 does not support adding freetype fonts. However, SDF can still be used on HTML5 by enabling it for a font through the IDE.

 

Syntax:

font_enable_sdf(ind, enable);

ArgumentTypeDescription
indFont AssetThe index of the font for which to enable/disable SDF rendering
enableBooleanWhether to enable SDF rendering for the font or not

 

Returns:

N/A

 

Example:

/// Create Event
new_font = font_add("STENCIL.TTF", 32, false, false, 32, 128);
font_enable_sdf(new_font, true);

/// Draw Event
draw_set_font(new_font);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);

var _sinval = dsin(current_time / 4);
var _scale = 4 * (1 + _sinval * 0.3);

draw_text_transformed(500, 400, "Hello World! (animated version)", _scale, _scale, 0);

The above code shows the code of an object's Create event and Draw event. In the Create event a custom font is added using font_add and stored in an instance variable new_font. SDF rendering is enabled for the font by calling font_enable_sdf.

In the Draw event, the font is set to new_font and text alignment is set to centred (both horizontally and vertically). Next some values are calculated to animate the text scale. Finally some text is drawn scaled using draw_text_transformed.

Because the font is SDF-enabled, this text should remain sharp as it scales up and down.