切換
舊版
前往
大廳
主題

【系統腳本】字體描繪追加 1.01 版

先行者 | 2012-06-10 18:12:48 | 巴幣 14 | 人氣 762

○檢視:
#==============================================================================
#----------------------------------------------------------------------------
# ○  OSD - 腳本討論社
#     Originality RGSS Discuss
#     └http://guild.gamer.com.tw/guild.php?sn=4707
#----------------------------------------------------------------------------
#==============================================================================
#--------------------------------------------------------------------------
# ● 腳本名稱:字體描繪追加
#--------------------------------------------------------------------------
# ● 腳本效果:
#     在一般描繪字體中追加一些特殊功能。
#--------------------------------------------------------------------------
# ● 腳本版本:1.01 版
#--------------------------------------------------------------------------
# ● 腳本更新區塊:
#     1.01版
#     └修正無法用 Window_Message 內建指令更改文字顏色 bug
#     └新增可更改光暈顏色的功能
#--------------------------------------------------------------------------
#==============================================================================
#----------------------------------------------------------------------------
# ○  OSD - 腳本討論社
#     Originality RGSS Discuss
#     └http://guild.gamer.com.tw/guild.php?sn=4707
#----------------------------------------------------------------------------
#==============================================================================

○使用方法:
#================================
○函式類
#================================
※※※※※※※※※※※※※※※※※※※※
draw_frame_text(x, y, width, height, text, align = 0)
描繪有邊框的字
※※※※※※※※※※※※※※※※※※※※
draw_light_text(x, y, width, height, text, align = 0)
描繪有光暈的字
※※※※※※※※※※※※※※※※※※※※
#================================
○變數類
#================================
※※※※※※※※※※※※※※※※※※※※
frame_color
可更改邊框顏色
※※※※※※※※※※※※※※※※※※※※
shadow_ox / shadow_oy
可更改陰影位移的多寡, shadow_ox 更改 X 座標shadow_oy 更改 Y 座標
※※※※※※※※※※※※※※※※※※※※
shadow_ok
是否開啟陰影效果, true 是 / false 否
※※※※※※※※※※※※※※※※※※※※
※※※※※※※※※※※※※※※※※※※※
light_color
可更改光暈顏色
※※※※※※※※※※※※※※※※※※※※

○腳本檢視:
#==============================================================================
#----------------------------------------------------------------------------
# ○  OSD - 腳本討論社
#     Originality RGSS Discuss
#     └http://guild.gamer.com.tw/guild.php?sn=4707
#----------------------------------------------------------------------------
#==============================================================================
#--------------------------------------------------------------------------
# ● 腳本名稱:字體描繪追加
#--------------------------------------------------------------------------
# ● 腳本效果:
#     在一般描繪字體中追加一些特殊功能。
#--------------------------------------------------------------------------
# ● 腳本版本:1.01 版
#--------------------------------------------------------------------------
# ● 腳本更新區塊:
#     1.01版
#     └修正無法用 Window_Message 內建指令更改文字顏色 bug
#     └新增可更改光暈顏色的功能
#--------------------------------------------------------------------------
#==============================================================================
#----------------------------------------------------------------------------
# ○  OSD - 腳本討論社
#     Originality RGSS Discuss
#     └http://guild.gamer.com.tw/guild.php?sn=4707
#----------------------------------------------------------------------------
#==============================================================================

#==============================================================================
# ■ Bitmap
#------------------------------------------------------------------------------
# 處理圖像的類別
#==============================================================================
class Bitmap
  #--------------------------------------------------------------------------
  # ● 定義實例變量
  #--------------------------------------------------------------------------
  attr_accessor :shadow_ox                  # 陰影 X 座標位移像素
  attr_accessor :shadow_oy                  # 陰影 Y 座標位移像素
  attr_accessor :shadow_ok                  # 陰影文字的開關
  attr_accessor :shadow_color               # 陰影文字陰影顏色
  attr_accessor :frame_color                # 邊框文字邊框顏色
  #--------------------------------------------------------------------------
  # ● 初始化目標
  #--------------------------------------------------------------------------
  alias initialize_osd initialize
  def initialize(*args)
    initialize_osd(*args)
    @shadow_ox = 2
    @shadow_oy = 2
    @shadow_ok = true
    @shadow_color = Color.new(0, 0, 0, 200)
    @frame_color = Color.new(0, 0, 0, 255)
  end
  #--------------------------------------------------------------------------
  # ● 修正原本描繪字體,增加陰影
  #--------------------------------------------------------------------------
  alias draw_text_old draw_text
  def draw_text(*args)
    # 獲取參數
    if args[0].is_a?(Rect)
      rect = args[0]
      text = args[1].to_s
      align = args[2].to_i
      text_x, text_y, text_width, text_height = rect.x, rect.y, rect.width, rect.height
    else
      text_x, text_y, text_width, text_height = args[0...4]
      text, align = args[4].to_s, args[5].to_i
    end
    # 如果有開啟陰影
    if @shadow_ok
      # 設定顏色
      font.color = @shadow_color
      # 描繪陰影
      draw_text_old(text_x + @shadow_ox, text_y + @shadow_oy, text_width, text_height, text, align)
      # 還原顏色
      font.color = Font.default_color
    end
    # 描繪原本字體
    draw_text_old(*args)
  end
  #--------------------------------------------------------------------------
  # ● 邊框描繪函式
  #--------------------------------------------------------------------------
  def draw_frame_text(x, y, width, height, text, align = 0)
    text_o, align_o = text.to_s, align.to_i
    # 設定顏色
    font.color = @frame_color
    # 描繪圈框
    draw_text_old(x - 1, y, width, height, text_o, align_o)
    draw_text_old(x, y - 1, width, height, text_o, align_o)
    draw_text_old(x + 1, y, width, height, text_o, align_o)
    draw_text_old(x, y + 1, width, height, text_o, align_o)
    draw_text_old(x + 1, y + 1, width, height, text_o, align_o)
    draw_text_old(x - 1, y - 1, width, height, text_o, align_o)
    draw_text_old(x + 1, y - 1, width, height, text_o, align_o)
    draw_text_old(x - 1, y + 1, width, height, text_o, align_o)
    # 還原顏色
    font.color = Font.default_color
    draw_text_old(x, y, width, height, text_o, align_o)
  end
  #--------------------------------------------------------------------------
  # ● 光暈描繪函式
  #--------------------------------------------------------------------------
  def draw_light_text(x, y, width, height, text, align = 0)
    text_o, align_o = text.to_s, align.to_i
    (1...4).each {|i|
      # 設定顏色
      font.color.alpha = font.size * 3 - i * font.size
      move = i
      # 描繪黑框
      draw_text_old(x - move, y, width, height, text_o, align_o)
      draw_text_old(x, y - move, width, height, text_o, align_o)
      draw_text_old(x + move, y, width, height, text_o, align_o)
      draw_text_old(x, y + move, width, height, text_o, align_o)
      draw_text_old(x + move, y + move, width, height, text_o, align_o)
      draw_text_old(x - move, y - move, width, height, text_o, align_o)
      draw_text_old(x + move, y - move, width, height, text_o, align_o)
      draw_text_old(x - move, y + move, width, height, text_o, align_o)
    }
    # 還原顏色透明度
    font.color.alpha = 255
    draw_text_old(x, y, width, height, text_o, align_o)
  end
end

○畫面


○範例下載:
下載點 1
下載點 2
送禮物贊助創作者 !
0
留言

創作回應

月見斐夜
常看到(*args),好像是帶入原變數一類的功能,可是還是搞不太懂,這到底是神馬東西=_=
2012-06-10 23:52:16
先行者
噢、大概是把原本一開始函式的參數帶入到自己後來改寫的函式上吧...只不過我覺得再照抄一次比較容易了解[e24]
2012-06-11 21:31:49
先行者
而且是參數而不是變數喔[e8]
2012-06-12 10:00:45
狂狂
[e23]像C 語言的 printf scanf 後面的argument 也是一樣東西
2012-06-12 14:29:54
狂狂
*args 實際上是array 存放傳入參數 而在C/C++ 可以看做Point


2012-06-12 14:41:45
先行者
按個讚[e12]
2012-06-15 22:33:15
其實畫邊框的函式,只需要
draw_text_old(x + 1, y + 1, width, height, text_o, align_o)
draw_text_old(x - 1, y - 1, width, height, text_o, align_o)
draw_text_old(x + 1, y - 1, width, height, text_o, align_o)
draw_text_old(x - 1, y + 1, width, height, text_o, align_o)
就行囉(內建的傷害數字顯示,數字的邊框就是用這個方法的)
2012-09-03 22:47:17
魅力魔幻
請問我只要第五行那個顏色跟字 要怎麼用屋屋 救命..!
2015-07-12 18:29:58

更多創作