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.

[Resolved] Problem formatting a script

Status
Not open for further replies.
I found a script on a Japanese website that puts a shadow around certain battle text text to make it more readable. The problem is, I don't know how to use it. Here's a screenshot of what it does.
http://f44.aaa.livedoor.jp/~ytomy/tkool ... lter01.jpg[/IMG]
And here's the script.
Code:
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#_/  ◆縁取り・影文字描画 - KGC_FrameShadowText◆
#_/----------------------------------------------------------------------------
#_/ draw_text を強化し、縁取りや影文字の描画機能を追加します。
#_/  Provides functions to draw texts which framed or dropped shadow.
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

=begin
┏━━━━ 搭載メソッド - Methods ━━━━━━━━━━━━━━━━━━━━━━━
┠─── Class - Bitmap ────────────────────────────
┃ draw_frame_text(x, y, width, height, string[, align, frame_color])
┃ draw_frame_text(rect, string[, align, frame_color])
┃   x, y          : 描画先座標    [Integer]
┃                   Destination.
┃   width, height : 描画サイズ    [Integer]
┃                   Size.
┃   rect          : 描画領域      [Rect]
┃                   Rectangle.
┃   string        : 描画文字列    [String]
┃                   Output text.
┃   align         : 文字整列形式  [Integer]
┃                   Alignment.
┃   frame_color   : 縁取り色      [Color]
┃                   Frame color.
┃ 周りを frame_color で縁取りした文字列を描画します。
┃ Draws a character string framed in 'frame_color'.
┃
┃ draw_shadow_text(x, y, width, height, string[, align, frame_color])
┃ draw_shadow_text(rect, string[, align, frame_color])
┃   x, y          : 描画先座標    [Integer]
┃                   Destination.
┃   width, height : 描画サイズ    [Integer]
┃                   Size.
┃   rect          : 描画領域      [Rect]
┃                   Rectangle.
┃   string        : 描画文字列    [String]
┃                   Output text.
┃   align         : 文字整列形式  [Integer]
┃                   Alignment.
┃   frame_color   : 縁取り色      [Color]
┃                   Frame color.
┃ 右下に影を落とした文字列を描画します。
┃ Draws a character string which drops shadow to lower right.
┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
=end

$imported = {} if $imported == nil
$imported["FrameShadowText"] = true

#==============================================================================
# â–  Bitmap
#==============================================================================

class Bitmap
  #--------------------------------------------------------------------------
  # ● 縁取り文字描画
  #     x, y, width, height, string[, align, frame_color]
  #     rect, string[, align, frame_color]
  #--------------------------------------------------------------------------
  def draw_frame_text(*args)
    # 引数判定
    if args[0].is_a?(Rect)
      if args.size >= 2 && args.size <= 4
        # 引数を処理用のローカル変数へコピー
        x, y = args[0].x, args[0].y
        width, height = args[0].width, args[0].height
        string = args[1]
        align = args[2].equal?(nil) ? 0 : args[2]
        frame_color = args[3].equal?(nil) ? Color.new(0, 0, 0) : args[3]
      else
        # 引数が不正ならエラーを吐く
        raise(ArgumentError, "wrong number of arguments(#{args.size} of #{args.size < 2 ? 2 : 4})")
        return
      end
    else
      if args.size >= 5 && args.size <= 7
        # 引数を処理用のローカル変数へコピー
        x, y, width, height = args
        string = args[4]
        align = args[5].equal?(nil) ? 0 : args[5]
        frame_color = args[6].equal?(nil) ? Color.new(0, 0, 0) : args[6]
      else
        # 引数が不正ならエラーを吐く
        raise(ArgumentError, "wrong number of arguments(#{args.size} of #{args.size < 5 ? 5 : 7})")
        return
      end
    end
    # 元の色を保存
    origin_color = font.color.dup
    # 縁取り
    font.color = frame_color
    draw_text(x - 1, y - 1, width, height, string, align)
    draw_text(x - 1, y + 1, width, height, string, align)
    draw_text(x + 1, y - 1, width, height, string, align)
    draw_text(x + 1, y + 1, width, height, string, align)
    # 元の色に戻す
    font.color = origin_color
    draw_text(x, y, width, height, string, align)
  end
  #--------------------------------------------------------------------------
  # ● 影文字描画
  #     x, y, width, height, string[, align, shadow_color]
  #     rect, string[, align, shadow_color]
  #--------------------------------------------------------------------------
  def draw_shadow_text(*args)
    # 引数判定
    if args[0].is_a?(Rect)
      if args.size >= 2 && args.size <= 4
        # 引数を処理用のローカル変数へコピー
        x, y = args[0].x, args[0].y
        width, height = args[0].width, args[0].height
        string = args[1]
        align = args[2].equal?(nil) ? 0 : args[2]
        shadow_color = args[3].equal?(nil) ? Color.new(0, 0, 0) : args[3]
      else
        # 引数が不正ならエラーを吐く
        raise(ArgumentError, "wrong number of arguments(#{args.size} of #{args.size < 2 ? 2 : 4})")
        return
      end
    else
      if args.size >= 5 && args.size <= 7
        # 引数を処理用のローカル変数へコピー
        x, y, width, height = args
        string = args[4]
        align = args[5].equal?(nil) ? 0 : args[5]
        shadow_color = args[6].equal?(nil) ? Color.new(0, 0, 0) : args[6]
      else
        # 引数が不正ならエラーを吐く
        raise(ArgumentError, "wrong number of arguments(#{args.size} of #{args.size < 5 ? 5 : 7})")
        return
      end
    end
    # 元の色を保存
    origin_color = font.color.dup
    # 影描画
    font.color = shadow_color
    draw_text(x + 2, y + 2, width, height, string, align)
    # 元の色に戻す
    font.color = origin_color
    draw_text(x, y, width, height, string, align)
  end
end
 
Status
Not open for further replies.

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