Project1
标题: 用图片数字替换文本数字怎么能实现? [打印本页]
作者: shengfeng 时间: 2020-11-13 16:19
标题: 用图片数字替换文本数字怎么能实现?
请教大神
作者: alexncf125 时间: 2020-11-13 21:09
本帖最后由 alexncf125 于 2020-11-14 13:58 编辑
图片放进Graphics/Systems文件夹
- class Window_Base < Window
- alias textnum_to_imgnum_process_escape_character process_escape_character
- def process_escape_character(code, text, pos)
- textnum_to_imgnum_process_escape_character(code, text, pos)
- case code.upcase
- when 'Z'
- process_draw_imgnum(obtain_escape_param(text), pos)
- end
- end
-
- def process_draw_imgnum(num, pos)
- draw_imgnum(num, pos[:x], pos[:y])
- pos[:x] += 13
- end
-
- def draw_imgnum(num, x, y)
- bitmap = Cache.system("Number")
- rect = Rect.new(13 * num, 0, 13, 16)
- contents.blt(x, y + 4, bitmap, rect)
- bitmap.dispose
- end
- end
复制代码
\Z[0]123\Z[4]567\Z[8]9
位置偏移问题已在脚本中修正, 图片没更新
如果你是想要自动替换而不是手动加\Z[]替换的话, 只能说抱歉了, 因为我不懂得弄~~
作者: 魔法丶小肉包 时间: 2020-11-14 12:48
自动替换其实思路很简单w提供一下我个人觉得比较简单的思路
首先呢,因为图片正好是做成0123456789的等距格式,所以很方便将其分割开来显示。
所以考虑在Window_Base里写
def draw_picture_number(name, index, x, y)
bitmap = Cache.system(name)
rect = Rect.new(index % 10 * 15, index / 10 * 15, 15, 15)
contents.blt(x, y, bitmap, rect, 255)
bitmap.dispose
end
def draw_picture_number(name, index, x, y)
bitmap = Cache.system(name)
rect = Rect.new(index % 10 * 15, index / 10 * 15, 15, 15)
contents.blt(x, y, bitmap, rect, 255)
bitmap.dispose
end
那么这样就分割开来了,index为0的时候就会绘制0这部分,为9的时候就会绘制9这部分...
而15则是间距问题,可以随便改的,我是对应自己使用的图片来定制w
接下来则是关键部分,Window_Base中的process_normal_character(c, pos)方法中的参数c固定是一个字符
那么就去匹配这个c,如果为数字的话,就执行draw_picture_number
所以就是
class Window_Base
def process_normal_character(c, pos)
text_width = text_size(c).width
if c =~ /(\d)/
draw_picture_number("Number", $1[0].to_i, pos[:x], pos[:y])
else
draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
end
pos[:x] += text_width
end
def draw_picture_number(name, index, x, y)
bitmap = Cache.system(name)
rect = Rect.new(index % 10 * 15, index / 10 * 15, 15, 15)
contents.blt(x, y, bitmap, rect, 255)
bitmap.dispose
end
end
class Window_Base
def process_normal_character(c, pos)
text_width = text_size(c).width
if c =~ /(\d)/
draw_picture_number("Number", $1[0].to_i, pos[:x], pos[:y])
else
draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
end
pos[:x] += text_width
end
def draw_picture_number(name, index, x, y)
bitmap = Cache.system(name)
rect = Rect.new(index % 10 * 15, index / 10 * 15, 15, 15)
contents.blt(x, y, bitmap, rect, 255)
bitmap.dispose
end
end
作者: alexncf125 时间: 2020-11-14 12:56
原来有process_normal_character这个方法
我都没留意没看到~~
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |