设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 13293|回复: 21
打印 上一主题 下一主题

[原创发布] 多功能字幕滚动

[复制链接]

Lv4.逐梦者

梦石
0
星屑
7946
在线时间
1182 小时
注册时间
2007-7-29
帖子
2055
跳转到指定楼层
1
发表于 2010-12-11 18:12:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 enghao_lim 于 2010-12-12 01:05 编辑

不多做介绍,就是强化的字幕滚动。

范例截图:




范例下载:
01 SkyDrive下载(请自行更改后辍名为*.rar即可)
02 多功能字幕滚动.rar (587.39 KB, 下载次数: 3463)

脚本:
  1. =begin
  2. 说明:

  3. 01 把字幕强化了,添加对话框的一些功能到里头去。
  4.    \f[字体]:更改字体
  5.    \c[颜色]:更改颜色,与默认对话框相同
  6.    \s[字体大小]:更改字体大小
  7.    \p[图片名称]:显示在picture文件夹下指定的图片
  8.    <b>字幕</b>:被包围的字将会变成粗体
  9.    <i>字幕</i>:被包围的字将会变成斜体
  10.    <left>:该行左边对齐
  11.    <center>:该行中间对齐
  12.    <right>:该行右边对齐

  13. 02 调用方法:(1) $scene = Scene_Credit.new
  14.              (2) $scene = Scene_Credit.new("文字")
  15.    (1) 为默认调用发,字幕会直接读取脚本里设定好的字幕
  16.    (2) 为更改字幕,字幕将变成设定的文字,支持\txt[TXT名称],将会读取
  17.        Credit文件夹底下的指定TXT,TXT格式参考范例。

  18. 03 其他玩转设置参考范例。

  19. =end
  20. module CREDIT

  21. # 字幕
  22. Subtitle=<<_end_
  23. 最普通的字幕显示

  24. 更改字幕的显示字体\\f[楷体]楷体\\f[微软雅黑]微软雅黑\\f[黑体]
  25. 更改\\c[1]字幕\\c[2]显示\\c[3]颜色\\c[0]
  26. \\s[16]更改\\s[48]字体的显示\\s[16]大小\\s[22]
  27. 图片显示:
  28. \\p[picture]
  29. <b>粗体字幕</b>
  30. <i>斜体字幕</i>
  31. <left>左边(上边)对齐
  32. <center>中间(中间)对齐
  33. <right>右边(下边)对齐
  34. _end_

  35. # 字幕移动方式 y 垂直移动,x 横着移动
  36. Subtitle_move = "y"

  37. # 允许按键推出
  38. AllowButtonExit = true

  39. # 边距
  40. MarginX = 20
  41. MarginY = 20

  42. # 背景
  43. Background = "" # 空着会调用背景颜色
  44. BackgroundRepeat = false # 背景循环 (背景移动时强行打开)
  45. BackgroundColor = Color.new(0,0,0) # 背景颜色
  46. BackgroundMoveX = 0 # 背景移动X值
  47. BackgroundMoveY = 0 # 背景移动Y值

  48. # 背景声音 放 "" 为没有声音
  49. BackgroundBGM = "017-Theme06"

  50. # 默认字体
  51. Font_name = "黑体" # 字体
  52. Font_size = 22 #大小
  53. Font_color = Color.new(255,255,255) # 颜色
  54. Font_bold = false # 是否粗体
  55. Font_italic = false # 是否斜体

  56. # 默认行高
  57. DefaultLineHeight = 32

  58. # 退出后回到的场景
  59. ExitScene = Scene_Map.new

  60. end

  61. class Scene_Credit
  62.   include CREDIT
  63.   def initialize(text = nil)
  64.     if text == nil
  65.       @text = Subtitle
  66.     else
  67.       text.gsub!(/\\[Tt][Xx][Tt]\[(\w+)\]/){"\001[#{$1}]"}
  68.       new_text = ""
  69.       while ((c = text.slice!(/./m)) != nil)
  70.         if c == "\001"
  71.           text.sub!(/\[(\w+)\]/,"")
  72.           name = "Credit/" + $1 + ".txt"
  73.           file = File.open(name)
  74.           a = file.readlines
  75.           for i in 1...a.size
  76.             new_text += a[i]
  77.           end
  78.           file.close
  79.         else
  80.           new_text += c
  81.         end
  82.       end
  83.       @text = new_text
  84.     end
  85.   end
  86.   def main
  87.     initialize_font_setting
  88.     if BackgroundRepeat or (BackgroundMoveX + BackgroundMoveY != 0)
  89.       @background = Plane.new
  90.     else
  91.       @background = Sprite.new
  92.     end
  93.     if Background != ""
  94.       @background.bitmap = RPG::Cache.picture(Background)
  95.     else
  96.       @background.bitmap = Bitmap.new(640,480)
  97.       @background.bitmap.fill_rect(0,0,640,480,BackgroundColor)
  98.     end
  99.     @subtitle = Sprite.new
  100.     process_credit(@text)
  101.     if BackgroundBGM != ""
  102.       Audio.bgm_play("Audio/BGM/#{BackgroundBGM}")
  103.     end
  104.     Graphics.transition
  105.     loop do
  106.       Graphics.update
  107.       Input.update
  108.       update
  109.       break if $scene != self
  110.     end
  111.     @subtitle.dispose
  112.     @background.dispose
  113.   end
  114.   def update
  115.     update_subtitle
  116.     if @background.is_a?(Plane)
  117.       @background.ox += BackgroundMoveX
  118.       @background.oy += BackgroundMoveY
  119.     end
  120.     if AllowButtonExit
  121.       if Input.trigger?(Input::B)
  122.         exit_scene
  123.       end
  124.     end
  125.   end
  126.   def update_subtitle
  127.     if Subtitle_move == "y"
  128.       @subtitle.y -= 1
  129.       exit_scene if @subtitle.y <= (-20 - @subtitle.bitmap.height)
  130.     else
  131.       @subtitle.x += 1
  132.       exit_scene if @subtitle.x >= (660)
  133.     end
  134.   end
  135.   def exit_scene
  136.     Audio.bgm_fade(800)
  137.     $scene = ExitScene
  138.   end
  139.   def initialize_font_setting
  140.     @align = 0
  141.     @font_size = Font_size
  142.     @font_name = Font_name
  143.     @font_color = Font_color
  144.     @font_bold = Font_bold
  145.     @font_italic = Font_italic
  146.   end
  147.   def process_credit(text)
  148.     text = text.split("\n")
  149.     if Subtitle_move == "y"
  150.       total_height = 0
  151.       for line in text
  152.         w,h = calc_line_rect(line)
  153.         total_height += h
  154.       end
  155.       initialize_font_setting
  156.       bitmap = Bitmap.new(640-2*MarginX,total_height)
  157.       y = 0
  158.       for line in text
  159.         w,h = calc_line_rect(line)
  160.         bitmap2 = create_line_bitmap(line,w,h)
  161.         rect = Rect.new(0,0,bitmap2.width,bitmap2.height)
  162.         x = @align == 0 ? 0 : @align == 1 ? (bitmap.width/2-bitmap2.width/2) : (bitmap.width-bitmap2.width)
  163.         bitmap.blt(x,y,bitmap2,rect)
  164.         y += h
  165.       end
  166.       @subtitle.bitmap = bitmap
  167.       @subtitle.x = MarginX
  168.       @subtitle.y = 481
  169.     else
  170.       total_width = 0
  171.       for line in text
  172.         w,h = calc_line_rect(line)
  173.         total_width += w
  174.       end
  175.       initialize_font_setting
  176.       bitmap = Bitmap.new(total_width,480-MarginY*2)
  177.       x = total_width
  178.       for line in text
  179.         w,h = calc_line_rect(line)
  180.         x -= w
  181.         bitmap2 = create_line_bitmap(line,w,h)
  182.         rect = Rect.new(0,0,bitmap2.width,bitmap2.height)
  183.         y = @align == 0 ? 0 : @align == 1 ? (bitmap.height/2-bitmap2.height/2) : (bitmap.height-bitmap2.height)
  184.         bitmap.blt(x,y,bitmap2,rect)
  185.       end
  186.       @subtitle.bitmap = bitmap
  187.       @subtitle.x = -total_width
  188.       @subtitle.y = MarginY
  189.     end
  190.   end
  191.   def calc_line_rect(line_text)
  192.     temp_bitmap = Bitmap.new(32,32)
  193.     temp_bitmap.font.name = @font_name
  194.     temp_bitmap.font.size = @font_size
  195.     temp_bitmap.font.color = @font_color
  196.     temp_bitmap.font.bold = @font_bold
  197.     temp_bitmap.font.italic = @font_italic
  198.     line = line_text.dup
  199.     height = 0
  200.     width = 0
  201.     line.gsub!(/\<[Cc][Ee][Nn][Tt][Ee][Rr]\>/){""}
  202.     line.gsub!(/\<[Rr][Ii][Gg][Hh][Tt]\>/){""}
  203.     line.gsub!(/\<[Ll][Ee][Ff][Tt]\>/){""}
  204.     line.gsub!(/\\\\/){"\000"}
  205.     line.gsub!(/\\[Ff]\[(\w+)\]/){"\001[#{$1}]"}
  206.     line.gsub!(/\\[Cc]\[(\d+)\]/){"\002[#{$1}]"}
  207.     line.gsub!(/\\[Ss]\[(\d+)\]/){"\003[#{$1}]"}
  208.     line.gsub!(/\\[Pp]\[(\w+)\]/){"\004[#{$1}]"}
  209.     line.gsub!(/\<[Bb]\>/){"\201"}
  210.     line.gsub!(/\<\/[Bb]\>/){"\202"}
  211.     line.gsub!(/\<[Ii]\>/){"\203"}
  212.     line.gsub!(/\<\/[Ii]\>/){"\204"}
  213.     while ((c = line.slice!(/./m)) != nil)
  214.       if c == "\000"
  215.         c = "\\"
  216.       elsif c == "\001"
  217.         line.sub!(/\[(\w+)\]/,"")
  218.         font_name = $1 == nil ? Font_name : $1
  219.         temp_bitmap.font.name = @font_name = font_name
  220.       elsif c == "\003"
  221.         line.sub!(/\[(\d+)\]/,"")
  222.         font_size = $1 == nil ? @font_size : [[$1.to_i,16].max,96].min
  223.         temp_bitmap.font.size = @font_size = font_size
  224.       elsif c == "\004"
  225.         line.sub!(/\[(\w+)\]/,"")
  226.         bitmap_name = $1 == nil ? "" : $1
  227.         if bitmap_name != ""
  228.           _temp_bitmap = RPG::Cache.picture(bitmap_name)
  229.           if Subtitle_move == "y"
  230.             width += _temp_bitmap.width
  231.             height = _temp_bitmap.height > height ? _temp_bitmap.height : height
  232.           else
  233.             width = _temp_bitmap.width > width ? _temp_bitmap.width : width
  234.             height += _temp_bitmap.height
  235.           end
  236.           _temp_bitmap.clear
  237.           _temp_bitmap.dispose
  238.           _temp_bitmap = nil
  239.         end
  240.       elsif c == "\201"
  241.         temp_bitmap.font.bold = @font_bold = true
  242.       elsif c == "\202"
  243.         temp_bitmap.font.bold = @font_bold = false
  244.       elsif c == "\203"
  245.         temp_bitmap.font.italic = @font_italic = true
  246.       elsif c == "\204"
  247.         temp_bitmap.font.italic = @font_italic = false
  248.       else
  249.         if Subtitle_move == "y"
  250.           width += temp_bitmap.text_size(c).width
  251.           height = temp_bitmap.text_size(c).height > height ?\
  252.                    temp_bitmap.text_size(c).height : height
  253.         else
  254.           width = temp_bitmap.text_size(c).width > width ?\
  255.                   temp_bitmap.text_size(c).width : width
  256.           height += temp_bitmap.text_size(c).height
  257.         end
  258.       end
  259.     end
  260.     if Subtitle_move == "y"
  261.       height = DefaultLineHeight if height < DefaultLineHeight
  262.       width = 32 if width == 0
  263.     else
  264.       width = DefaultLineHeight if width < DefaultLineHeight
  265.       height = 32 if height == 0
  266.     end
  267.     temp_bitmap.clear
  268.     temp_bitmap.dispose
  269.     temp_bitamp = nil
  270.     return width,height
  271.   end
  272.   def create_line_bitmap(line,width,height)
  273.     temp_bitmap = Bitmap.new(width,height)
  274.     temp_bitmap.font.name = @font_name
  275.     temp_bitmap.font.size = @font_size
  276.     temp_bitmap.font.color = @font_color
  277.     temp_bitmap.font.bold = @font_bold
  278.     temp_bitmap.font.italic = @font_italic
  279.     x = 0
  280.     line = line.dup
  281.     line.gsub!(/\<[Cc][Ee][Nn][Tt][Ee][Rr]\>/){"\101"}
  282.     line.gsub!(/\<[Rr][Ii][Gg][Hh][Tt]\>/){"\102"}
  283.     line.gsub!(/\<[Ll][Ee][Ff][Tt]\>/){"\100"}
  284.     line.gsub!(/\\\\/){"\000"}
  285.     line.gsub!(/\\[Ff]\[(\w+)\]/){"\001[#{$1}]"}
  286.     line.gsub!(/\\[Cc]\[(\d+)\]/){"\002[#{$1}]"}
  287.     line.gsub!(/\\[Ss]\[(\d+)\]/){"\003[#{$1}]"}
  288.     line.gsub!(/\\[Pp]\[(\w+)\]/){"\004[#{$1}]"}
  289.     line.gsub!(/\<[Bb]\>/){"\201"}
  290.     line.gsub!(/\<\/[Bb]\>/){"\202"}
  291.     line.gsub!(/\<[Ii]\>/){"\203"}
  292.     line.gsub!(/\<\/[Ii]\>/){"\204"}
  293.     while ((c = line.slice!(/./m)) != nil)
  294.       if c == "\100"
  295.         @align = 0
  296.       elsif c == "\101"
  297.         @align = 1
  298.       elsif c == "\102"
  299.         @align = 2
  300.       elsif c == "\000"
  301.         c = "\\"
  302.       elsif c == "\001"
  303.         line.sub!(/\[(\w+)\]/,"")
  304.         font_name = $1 == nil ? Font_name : $1
  305.         temp_bitmap.font.name = @font_name = font_name
  306.       elsif c == "\002"
  307.         line.sub!(/\[(\d+)\]/,"")
  308.         font_color = $1 == nil ? 0 : $1.to_i
  309.         case font_color
  310.         when 1
  311.           temp_bitmap.font.color = @font_color = Color.new(128,128,255)
  312.         when 2
  313.           temp_bitmap.font.color = @font_color = Color.new(255,128,128)
  314.         when 3
  315.           temp_bitmap.font.color = @font_color = Color.new(128,255,128)
  316.         when 4
  317.           temp_bitmap.font.color = @font_color = Color.new(128,255,255)
  318.         when 5
  319.           temp_bitmap.font.color = @font_color = Color.new(255,128,255)
  320.         when 6
  321.           temp_bitmap.font.color = @font_color = Color.new(255,255,128)
  322.         when 7
  323.           temp_bitmap.font.color = @font_color = Color.new(192,192,192)
  324.         else
  325.           temp_bitmap.font.color = @font_color = Color.new(255,255,255)
  326.         end
  327.       elsif c == "\003"
  328.         line.sub!(/\[(\d+)\]/,"")
  329.         font_size = $1 == nil ? @font_size : [[$1.to_i,16].max,96].min
  330.         temp_bitmap.font.size = @font_size = font_size
  331.       elsif c == "\004"
  332.         line.sub!(/\[(\w+)\]/,"")
  333.         bitmap_name = $1 == nil ? "" : $1
  334.         if bitmap_name != ""
  335.           _temp_bitmap = RPG::Cache.picture(bitmap_name)
  336.           rect = Rect.new(0,0,_temp_bitmap.width,_temp_bitmap.height)
  337.           if Subtitle_move == "y"
  338.             temp_bitmap.blt(x,height/2-_temp_bitmap.height/2,_temp_bitmap,rect)
  339.           else
  340.             temp_bitmap.blt(width/2-_temp_bitmap.width/2,x,_temp_bitmap,rect)
  341.           end
  342.           _temp_bitmap.clear
  343.           _temp_bitmap.dispose
  344.           _temp_bitmap = nil
  345.         end
  346.       elsif c == "\201"
  347.         temp_bitmap.font.bold = @font_bold = true
  348.       elsif c == "\202"
  349.         temp_bitmap.font.bold = @font_bold = false
  350.       elsif c == "\203"
  351.         temp_bitmap.font.italic = @font_italic = true
  352.       elsif c == "\204"
  353.         temp_bitmap.font.italic = @font_italic = false
  354.       else
  355.         if Subtitle_move == "y"
  356.           temp_bitmap.draw_text(x,0,temp_bitmap.text_size(c).width,height,c)
  357.           x += temp_bitmap.text_size(c).width
  358.         else
  359.           temp_bitmap.draw_text(0,x,width,temp_bitmap.text_size(c).height,c,1)
  360.           x += temp_bitmap.text_size(c).height
  361.         end
  362.       end
  363.     end
  364.     return temp_bitmap
  365.   end
  366. end
复制代码

评分

参与人数 2星屑 +20 收起 理由
1105741847 + 6 good
某死灵法师 + 14 好脚本,拿下!

查看全部评分

Lv3.寻梦者 (暗夜天使)

名侦探小柯

梦石
0
星屑
3263
在线时间
3616 小时
注册时间
2006-9-6
帖子
37399

开拓者贵宾第3届短篇游戏大赛主流游戏组亚军第5届短篇游戏比赛亚军

2
发表于 2010-12-11 23:19:16 | 只看该作者
这个加强版比原来的好多了啊。
可以支持多字幕(读txt很神),还能对字体进行处理并显示图片……还可以横版移动
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
60
在线时间
29 小时
注册时间
2006-9-17
帖子
236
3
发表于 2010-12-12 13:26:20 | 只看该作者
不错支持一下。
欢迎光临吞食天地大同盟http://www.twkunion.com/
《游戏制作军工厂》QQ群:41792464
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
202 小时
注册时间
2009-9-6
帖子
307
4
发表于 2011-1-16 12:03:12 | 只看该作者
又是XP的神物,收下咯~
   .black-box//
-------------制作准备中
小血的百度博客
小血的腾讯博客
小血的新浪微博
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
111 小时
注册时间
2010-7-6
帖子
197
5
发表于 2011-1-16 12:14:35 | 只看该作者
刚好愁这货,谢了。。。。。。

广告位招租,有意请加QQ:928545621
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
25 小时
注册时间
2010-3-21
帖子
69
6
发表于 2011-1-16 19:15:44 | 只看该作者
围观~~~~

点评

这家伙灌水,版主,扣他分啊!  发表于 2012-8-13 11:18
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
7 小时
注册时间
2010-10-10
帖子
40
7
发表于 2011-1-18 16:07:44 | 只看该作者
不错支持一下。
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
432
在线时间
4175 小时
注册时间
2010-6-26
帖子
6474
8
发表于 2012-3-7 20:11:55 | 只看该作者
本帖最后由 eve592370698 于 2012-3-7 20:12 编辑

我在试着把滚动字幕整合到FUKI对话框中。您的我正好研究研究。



目前来说滚动字幕最大的缺陷就是还不支持在当前地图下字幕的滚动,这是最大的麻烦。


不过VA的默认滚动字幕功能有限,想过把这些功能移植到VA上吗?
潜水,专心忙活三次元工作了……
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
225
在线时间
4 小时
注册时间
2012-2-18
帖子
2
9
发表于 2012-3-9 19:19:39 | 只看该作者
非常帮!

评分

参与人数 1星屑 -10 收起 理由
Kimu -10

查看全部评分

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
55 小时
注册时间
2007-7-11
帖子
107
10
发表于 2012-3-12 13:47:43 | 只看该作者
这玩意太神了!!我喜欢!!!

评分

参与人数 1星屑 -10 收起 理由
Kimu -10

查看全部评分

金庸群侠传-我是传奇,全新的开始。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-8 08:54

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表