| 赞 | 35 |
| VIP | |
| 好人卡 | |
| 积分 | 64 |
| 经验 | |
| 最后登录 | 2025-12-12 |
| 在线时间 | 1473 小时 |
- 梦石
- 0
- 星屑
- 6375
- 在线时间
- 1473 小时
- 注册时间
- 2015-7-25
- 回帖
- 609
 
|
发表于 2020-11-14 12:48:10
|
显示全部楼层
自动替换其实思路很简单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
复制代码
那么这样就分割开来了,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
复制代码
|
|