Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Draw text with line breaks
- - By chase4926 Date 2013-09-05 18:22
So I needed this functionality for the current project I'm working on (see: Vortex Voyager).

Here it is, go crazy:
module Gosu
  class Font
    def draw_with_linebreaks(text, x, y, z, factor_x = 1, factor_y = 1, color = 0xffffffff, mode = :default, y_padding=0)
      text.split("\n").each_with_index() do |line, i|
        self.draw(line, x, y+(i*(self.height+y_padding)), z, factor_x, factor_y, color, mode)
Parent - - By jahmaican Date 2013-09-06 06:53
Docs suggest using Image::from_text method for longer texts. It handles line breaks and I suppose might perform better.
Parent - By chase4926 Date 2013-09-06 13:39
Would perform slightly better, thanks for the suggestion!
Not sure I'll use it, because I think I need dynamic lines of text. (And it would be kind of weird just updating the image)
Parent - By Spooner Date 2013-09-07 11:07
You can't manage your own line-spacing with that method though. It would perform better if the text was static, but if it was changing (e.g. if you were adding a few characters a second) it would create a lot of new Image objects. Still, valid to mention it!
Parent - By ml Date 2013-09-10 02:13
Cool! I will definitely be trying this out!
Up Topic Gosu / Gosu Exchange / Draw text with line breaks

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill