Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Draw Text

Does anyone know the scripting for the draw_text command in the bitmap class?

This is very important for a script I'm making.

Thanks in advance ^_^

Syvkal
 
Read the help file

Code:
bitmap.draw_text(x, y, width, height, text, align)
bitmap.draw_text(rect, text, align)

You specify a rectange, either a Rect object or parameters of a rect. Then a string is your text. Align can be omitted as defaults to left align (0). You only need to specify align if you want it centered (1) or right aligned (2) in the rect you specify.
 
I definitely found the code for bitmap somewhere on the web, because I know people have definitely modified and extended it's methods. I just can't remember for the life of me where.
 
You can extend and modify methods without knowing the original code.

Code:
class Bitmap
  alias draw_shadow draw_text
  def draw_text(x, y, w, h, string, align = 0, shadow = false)
    if shadow
      col = self.font.color.clone
      self.font.color = Color.new(0, 0, 0)
      draw_shadow(x + 1, y + 1, w, h, string, align)
      self.font.color = col
    end
    draw_shadow(x, y, w, h, string, align)
  end
end

There, extended the method to draw shadows. I definitely don't know the original code :)
 
Ah thanks, that actually helps a bit.
Just one question to Prexus, or anyone.
You know the x, y, w, h and all that? What are used in the draw_text command?
Is it draw_text(x, y, w, h, string, align = 0)
Or is it draw_text(rect, string)?
 
It's draw_text(*args)

*args lets any amount of arguements be given, you then process them in the method.

Code:
def draw_text(*args)
  if args[0].is_a?(Rect)
    draw_shadow(args[0].x, args[0].y, args[0].width, args[0].height, args[1], args[2])
  elsif args[0].is_a?(Integer)
    draw_shadow(args[0], args[1], args[2], args[3], args[4], args[5])
  end
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top