GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2017-08-23 13:53:07

matharoo
Member
Registered: 2017-08-23
Posts: 3

draw_text_diffont() - Draw text with different fonts for numbers

This script takes two fonts, where one is used for the numbers in the text and one for the letters.

Example

I made this script for someone who wanted this feature in their game, and so I thought it could be helpful to others, so thought why not put it out on the internet. smile

Expand/// draw_text_diffont(x, y, text, numbers_font, letters_font)
//
// Draws text with two different fonts combined: one for numbers and one for letters
//
// x                x position for text
// y                y position for text
// text             text to be drawn
// numbers_font     font used for numbers
// letters_font     font used for letters
//

//Argument vars
var xx = argument0;
var yy = argument1;
var text = argument2;
var n_font = argument3;
var l_font = argument4;

//String length
var str_len = string_length(text);
//Drawn text width
var drawn_w = 0;

for(var i=1; i<=str_len; i++){
    //get current letter
    var letter = string_copy(text, i, 1);
    //set font
    if (string_digits(letter)!=""){
        draw_set_font(n_font);
    }else{
        draw_set_font(l_font);
    }
    //draw letter
    draw_text(xx + drawn_w, yy, letter);
    //increase drawn width
    drawn_w += string_width(letter);
}

Thanks!

Offline

#2 2017-08-24 21:20:48

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: draw_text_diffont() - Draw text with different fonts for numbers

Very interesting script. It's not something I would have ever thought of making but I could see this helping somebody.

Thanks for the submission and welcome to the forums.


Abusing forum power since 1986.

Offline

#3 2017-08-30 11:05:01

matharoo
Member
Registered: 2017-08-23
Posts: 3

Re: draw_text_diffont() - Draw text with different fonts for numbers

Thanks smile Have a good day life.

Offline

#4 2017-08-30 11:08:24

matharoo
Member
Registered: 2017-08-23
Posts: 3

Re: draw_text_diffont() - Draw text with different fonts for numbers

xot wrote:

Very interesting script. It's not something I would have ever thought of making but I could see this helping somebody.

Thanks for the submission and welcome to the forums.

I don't know how this site works, so I have a question. Is this where the script belongs now, in this thread, or will it be added to the Scripts section of the website?

Thanks.

Offline

Board footer

Powered by FluxBB