Jump to content


Photo

draw_text and draw_text_ext simply do not work.


  • Please log in to reply
2 replies to this topic

#1 Kayle

Kayle

    GMC Member

  • GMC Member
  • 34 posts
  • Version:GM8

Posted 30 July 2012 - 02:53 AM

I've posted about this problem in the other QnA forum but it wasn't dedicated to this issue, and I kind of left it alone.

Trying to give the background briefly: I've created a text handler object that, when given a string after creation, it displays that string one character at a time at the specified location, using string_copy. The text does not display. I've used debug mode to verify that string_copy does work, it's being given the string. I've added draw_text to other places in the game where draw_sprite is working (in the draw event, naturally); doesn't work. I've removed all other instances except the text_handler, to ensure that depth was not a problem. Doesn't work. I don't understand what could possibly be causing this, or how to get around it.

Here's all the code that goes into the text_handler:


CREATE:
text = ""; //The text to be drawn
text_speed = .5; //Handled like image_speed. Almost always 1.
char_num = 0; //Which character are we on? 

w = 0; //Maximum number of characters - not the width of the region.
h = 0; //Maximum number of lines - not the height of the region.

(h is currently unused.)

DRAW:
draw_set_font(HUD_font)
draw_set_color(33023);
draw_text_ext(x, y, string_copy(text, 0, char_num), -1, w)
char_num += text_speed;

Note: HUD_font is a font I created (it's just 7pt Courier) in the early stages of development for experimentation. I was able to display text with HUD_font at that time, in multiple places. I don't know what changed. I created a new font and changed no settings, and tried to use that one instead; no luck.


When the game is paused, the pause menu object creates a text handler; this is the code:

CREATE:
//text handler, 130, 27, 22, 4
weapon_desc = instance_create(130, 27, text_handler);
weapon_desc.text = "Example text for now"
weapon_desc.text_speed = 1
weapon_desc.w = 22

Any ideas?
  • 0

#2 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 30 July 2012 - 09:13 AM

There are some usual mistakes to render your text invisible: When draw_text draws nothing

A few of minor points:

draw_text_ext(x, y, string_copy(text, 0, char_num), -1, w)

It should be string_copy(text, 1, ...) as the character index of string in GML starts from 1, not 0. You may not realize the difference as long as you only use 0 or 1, but will get into problems if you try to take a middle of string.

The next one may be more related to the problem:

weapon_desc.w = 22

Isn't it too narrow space to render texts? Even with 7pt font, only 2 or 3 letters could fit within 22 pixels. (Considering that Courier is a relatively wide font, I doubt it can even contain three letters per line.) Chances are, your text is brought to all the way down because it can't find a point to break words.
  • 1

#3 Kayle

Kayle

    GMC Member

  • GMC Member
  • 34 posts
  • Version:GM8

Posted 30 July 2012 - 01:53 PM

Sorry, used to C-index arrays where everything starts at 0... ^ ^"

The next one may be more related to the problem:

weapon_desc.w = 22

Isn't it too narrow space to render texts? Even with 7pt font, only 2 or 3 letters could fit within 22 pixels. (Considering that Courier is a relatively wide font, I doubt it can even contain three letters per line.) Chances are, your text is brought to all the way down because it can't find a point to break words.


Not pixel width - character width. I didn't realize that's how _ext worked. That's convenient!

The topic you quoted had it - I'd forgotten that it needs to be view_xview + ... whoops. That works now, thank you!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users