Project1

标题: [脚本问题]字符串中不能用控制码换行! [打印本页]

作者: 风清翔    时间: 2015-1-23 22:35
标题: [脚本问题]字符串中不能用控制码换行!
我在脚本中这样写的:
@introduce_window.set_text("欢迎来到我的第一个窗口!\n这是我第一个脚本。",0)
其中使用了\n控制码来换页
游戏里却是这样的。

我尝试着把字符串代入变量里用,类似如此:
a="欢迎来到我的第一个窗口!\n这是我第一个脚本。"
@introduce_window.set_text(a,0)
但还是无效,无法换行,一个口摆在那里。

@introduce_window是一个窗口的类,里面关于显示文字的定义是这样的:
def set_text(text, align = 0)
if text != @text or align != @align
# 再描绘文本
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(0, 0, 500, 32, text, align)
@text = text
@align = align
@actor = nil
end
self.visible = true
end
(其实就是从Help里拉了一段……)

求助,怎么样才能让这段字符串能够用控制符换行?

另外:pan.baidu.com/s/1i37p4rV
这是那个工程,希望有了这个可以更快解决问题。(其实那工程里还有一个问题没解决,不过现在就不麻烦各位了。)
在标题界面进入第三个选项即可进入问题窗口
作者: 喵呜喵5    时间: 2015-1-24 00:02
忽然发现我在贴吧回复过一遍……


一直用的是VA,没用过XP,因为不知道XP应该怎么处理所以按照VA描绘文字的方式重新修改了你的Window_introduce,你自己看看吧
  1. class Window_introduce < Window_Base
  2.   def initialize
  3.     super(80,80,640-160,480-160)
  4.     self.back_opacity = 160
  5.     self.opacity = 160
  6.     self.contents_opacity = 255
  7.     self.contents = Bitmap.new(width - 32, height - 32)
  8.   end  
  9.   def set_text(text, align = 0)
  10.     if text != @text or align != @align      
  11.       self.contents.clear
  12.       self.contents.font.color = normal_color      
  13.       # 获取描绘区域的属性
  14.       # x,y:当前文字描绘的位置
  15.       # width,height:描绘文字区域的宽度和高度
  16.       # new_x:每行文字的开始x坐标
  17.       pos = {
  18.         :x => 0,:y => 0,
  19.         :new_x => 0,:width => 500,:height => 32,
  20.       }
  21.       # 按照顺序依次描绘文字
  22.       text.scan(/./).each {|c| process_character(c,pos) }
  23.       @text,@align = text,align      
  24.     end
  25.     self.visible = true
  26.   end
  27.   def process_character(c,pos)   
  28.     case c
  29.     # 若文字为“/”则换行
  30.     when '/'
  31.       pos[:x] = pos[:new_x]
  32.       pos[:y] += pos[:height]
  33.     # 处理正常文字
  34.     else
  35.       # 获取文字大小
  36.       size = self.contents.text_size(c)
  37.       # 描绘文字
  38.       self.contents.draw_text(pos[:x],pos[:y],pos[:width],pos[:height], c)
  39.       # 计算下一个文字的描绘位置
  40.       pos[:x] += size.width
  41.     end
  42.   end
  43. end
复制代码

作者: RyanBern    时间: 2015-1-24 09:12
这玩意果然还是有点用处的:
https://rpg.blue/thread-374240-1-3.html
作者: 风清翔    时间: 2015-1-24 13:12
喵呜喵5 发表于 2015-1-24 00:02
忽然发现我在贴吧回复过一遍……

有效了!又学到了一些东西,谢谢了!
作者: 英顺的马甲    时间: 2015-1-24 15:27
如果只是单纯的文字的话可以考虑用each_line或者split("\n")来分别画每一行




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1