Jump to content


Photo

Draw smooth strings


  • Please log in to reply
5 replies to this topic

#1 Jobo

Jobo

    No neurons left today

  • GMC Member
  • 2405 posts
  • Version:GM:Studio

Posted 17 May 2012 - 09:24 PM

Are you tired of choppy strings in Game Maker?
Standard windows fonts look generally bad and pixelated?

Solution: Use this script instead of draw_text(...)!

I wrote this for a game and figured other people may find it useful.
So here it is.

Enjoy.

/*

    Created by Jobo
    @ Game Maker Community (www.gmc.yoyogames.com)

    draw_string(x, y, smoothness, string, color);

    Usage: draw a smooth string
    
*/

var textX, textY, Smoothness, String, Alpha, Color;
textX = argument0;
textY = argument1;
Smoothness = argument2; // 1 is a good default
String = argument3;
Alpha = draw_get_alpha();
Color = draw_get_color();

draw_set_color(argument4);

for(i = 0; i < Smoothness; i += 1) {
    draw_set_alpha(max(0.1 ,i / Smoothness)); // Avoid 0 / Smoothness
    draw_text(textX - (Smoothness - i), textY - (Smoothness - i), String); // Draw string offset in upper-left corner
    draw_text(textX + (Smoothness - i), textY + (Smoothness - i), String); // Draw string offset in lower-right corner
    draw_text(textX - (Smoothness - i), textY + (Smoothness - i), String); // Draw string offset in lower-left corner
    draw_text(textX + (Smoothness - i), textY - (Smoothness - i), String); // Draw string offset in upper-right corner
}

// Reset global alpha value
draw_set_alpha(Alpha);

// Draw original string
draw_text(textX, textY, String);

// Reset global draw color
draw_set_color(Color);

  • 0

#2 DarkEraSky

DarkEraSky

    GMC Member

  • New Member
  • 9 posts

Posted 28 May 2012 - 07:28 PM

Thanks for posting this, it works great.
they ought to make something like this a game maker function.
  • 0

#3 Drara

Drara

    GMC Member

  • GMC Member
  • 294 posts

Posted 28 May 2012 - 07:43 PM

Thanks for posting this, it works great.
they ought to make something like this a game maker function.

Ehm.. they kinda made that. It's called anti-aliasing. In Gm 8.1 you can set your value of "smoothness" when creating the font.
  • 0

#4 Jobo

Jobo

    No neurons left today

  • GMC Member
  • 2405 posts
  • Version:GM:Studio

Posted 28 May 2012 - 08:52 PM

While Drara is correct, and I wrote this script for usage in GM8.0, GM8.1 and after only allows anti-aliasing of 0-3.
This script does not set anti-aliasing as much as it sets actual smoothness.

Be aware that the higher level of smoothness you apply to it, the string will grow accordingly.
  • 0

#5 NukeTheCat

NukeTheCat

    GMC Member

  • GMC Member
  • 461 posts
  • Version:GM8.1

Posted 15 June 2012 - 07:04 PM

So this basically draw the same string over and over, creating smooth layers? Cool!

Here's something you can add so that the user doesn't add 0:

if Smoothness > 0{
for(i = 0; i < Smoothness; i += 1) {
    draw_set_alpha(max(0.1 ,i / Smoothness)); // Avoid 0 / Smoothness
    draw_text(textX - (Smoothness - i), textY - (Smoothness - i), String); // Draw string offset in upper-left corner
    draw_text(textX + (Smoothness - i), textY + (Smoothness - i), String); // Draw string offset in lower-right corner
    draw_text(textX - (Smoothness - i), textY + (Smoothness - i), String); // Draw string offset in lower-left corner
    draw_text(textX + (Smoothness - i), textY - (Smoothness - i), String); // Draw string offset in upper-right corner
}
else
{
show_debug("YOU STUPID! YOU CAN'T DIVIDE 0!!!!"
}

  • 0

#6 Jobo

Jobo

    No neurons left today

  • GMC Member
  • 2405 posts
  • Version:GM:Studio

Posted 15 June 2012 - 09:03 PM

Not much of an issue as long as you go 0 / X and not X / 0. 0 / X will return 0 as far as I know.
As you can see;
draw_set_alpha(max(0.1 ,i / Smoothness));

Edited by Jobo, 15 June 2012 - 09:04 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users