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.

Outlining Text

Anonymous

Guest

I've created a script that (once it works) will put outlines around text, but all that is happening now is that fonts get thicker and letters get darker as they go along. It's hard to describe. I'd post a picture, but I'm on 56K. :( Would someone please help me with this?

Code:
class Bitmap
  alias old_draw_text draw_text
  def draw_text(x, y, w, h, s, a=0)
    @colour = font.color
    rr = @colour.red - 100
    gg = @colour.green - 100
    bb = @colour.blue - 100
    font.color = Color.new(rr, gg, bb, 255)
    old_draw_text(x + 1, y + 1, w, h, s, a)
    old_draw_text(x - 1, y - 1, w, h, s, a)
    old_draw_text(x - 1, y + 1, w, h, s, a)
    old_draw_text(x + 1, y - 1, w, h, s, a)
    font.color = @colour
    old_draw_text(x + 0, y + 0, w, h, s, a)
  end
end

Thank you in advance for taking the time to see this topic!^_^
 
Um, grab my Inns/Facesets script in my sig. I've got a module in it that also does the 'outline' thing... as well as shadows, 3-d and etc. Should be simple to just rip that out of it.

ps. I'm on 56 myself :D
 

Anonymous

Guest

The problem is, though, that I'm trying to outline EVERY text in the game. And I don't see what I'm doing wrong- It's just a redefine. And thank you for trying to help, but I looked in your system, and all it said was the
Code:
    old_draw_text(x + 1, y + 1, w, h, s, a)
    old_draw_text(x - 1, y - 1, w, h, s, a)
    old_draw_text(x - 1, y + 1, w, h, s, a)
    old_draw_text(x + 1, y - 1, w, h, s, a)
    old_draw_text(x + 0, y + 0, w, h, s, a)
section. Unless I read it wrong ¬_¬. Sorry, and thanks anyway! Can anyone else give it a try?
 
Okay, then try this...

Oh, and I use the font.color.dup statement myself (that could be it)...
Code:
class Bitmap
  #--------------------------------------------------------------------------
  # * Alias Draw_Text (Use original "Draw_Text" command by calling as "Text"
  #--------------------------------------------------------------------------
  alias :text :draw_text
  #--------------------------------------------------------------------------
  # * Draw_Text
  #--------------------------------------------------------------------------
  def draw_text(x, y=0, wd=0, ht=0, text=nil, align=0,
    outline = Color.new(0, 0, 0, 255))
    # If drawing with a rectangle command
    if x.is_a?(Rect)
      @x = x.x
      @y = x.y
      @wd = x.width
      @ht = x.height
      @text = y
      @align = wd
    # If drawing with regular command  
    else
      @x = x
      @y = y
      @wd = wd
      @ht = ht
      @text = text
      @align = align
    end
    #--------------------------------------------------------------------------
    # * Outlined Effect
    #--------------------------------------------------------------------------
    base_clr = font.color.dup
    font.color = outline
    text(@x+1, @y, @wd, @ht, @text, @align)
    text(@x-1, @y, @wd, @ht, @text, @align)
    text(@x, @y+1, @wd, @ht, @text, @align)
    text(@x, @y-1, @wd, @ht, @text, @align)
    font.color = base_clr
    text(@x, @y, @wd, @ht, @text, @align)
  end
end
Code:
class Bitmap
  #--------------------------------------------------------------------------
  # * Alias Draw_Text (Use original "Draw_Text" command by calling as "Text"
  #--------------------------------------------------------------------------
  alias :text :draw_text
  #--------------------------------------------------------------------------
  # * Draw_Text
  #--------------------------------------------------------------------------
  def draw_text(x, y=0, wd=0, ht=0, text=nil, align=0)
    # If drawing with a rectangle command
    if x.is_a?(Rect)
      @x = x.x
      @y = x.y
      @wd = x.width
      @ht = x.height
      @text = y
      @align = wd
    # If drawing with regular command  
    else
      @x = x
      @y = y
      @wd = wd
      @ht = ht
      @text = text
      @align = align
    end
    #--------------------------------------------------------------------------
    # * Outlined Effect
    #--------------------------------------------------------------------------
    base_clr = font.color.dup
    rr = base_clr.red - 100
    gg = base_clr.green - 100
    bb = base_clr.blue - 100
    font.color = Color.new(rr, gg, bb, 255)
    text(@x+1, @y, @wd, @ht, @text, @align)
    text(@x-1, @y, @wd, @ht, @text, @align)
    text(@x, @y+1, @wd, @ht, @text, @align)
    text(@x, @y-1, @wd, @ht, @text, @align)
    font.color = base_clr
    text(@x, @y, @wd, @ht, @text, @align)
  end
end

By this point, my cut-down outline will be reminiscent of Tsunokiette's Text Variations v.2 (Nov 23, 2005)... well... lots of it.

Also note that both scripts have an if...else block of code to recognize 'rect-drawn' text from regularly called text commands.

My version uses an extra argument for the outline effect that you can change in a 'text' command. With yours... I implemented your color - 100 system which lowers the color by 100 points... graying it.
 

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