| 赞 | 189 |
| VIP | |
| 好人卡 | |
| 积分 | 96 |
| 经验 | |
| 最后登录 | 2026-5-4 |
| 在线时间 | 5074 小时 |
- 梦石
- 0
- 星屑
- 9557
- 在线时间
- 5074 小时
- 注册时间
- 2013-6-21
- 回帖
- 3459
  
|
发表于 2015-6-22 23:15:43
|
显示全部楼层
如果是建立功能比较简单的窗口,要使用类似的写法,不过不能使用Window.new这样的写法,应该使用RGSS的Window_Base类。
记得写在 Scene_XXX里面
[pre lang="Ruby"]@bl = Window_Base.new(x坐标, y坐标, 宽, 高)
@bl.contents = Bitmap.new(@bl.width - 32, @bl.height - 32)
@bl.contents.draw_text(x, y, 宽, 高, 内容[, 对齐方式])[/pre]
用完这个窗口后,一定要记得释放,一般是在Scene_XXX主循环结束之后就要释放。
如果建立功能比较复杂的窗口,建议单独开一个类。
[pre lang="Ruby"]class Window_MyWindow < Window_Base
def initialize
super(0, 0, 300, 200)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
self.contents.draw_text(4, 0, 160, 32, "测试文字")
end
end[/pre]
要使用窗口,例如要在地图场景中,当地图ID为2的时候显示,其他情况下不显示,就要在Scene_Map上修改。
为了使得代码简洁,我们采用alias写法,当然,写好的脚本必须要放在Scene_Map这组脚本之后。
[pre lang="Ruby"]class Scene_Map
alias rb_main_20150622 main
def main
@test_window = Window_MyWindow.new
rb_main_20150622
@test_window.dispose
end
alias rb_update_20150622 update
def update
@test_window.update
rb_update_20150622
end
end
[/pre]
这样窗口算是接入了,但是我们要求只有当地图ID为2的时候才显示,所以我们还需要追加定义下面的脚本。下面的脚本和第一段写Window_MyWindow类的脚本写在一起就好了。
[pre lang="Ruby"]class Window_MyWindow < Window_Base
def update
super
self.visible = $game_map.map_id == 2
end
end[/pre]
上面那段写完就大功告成了!插入试试效果吧。 |
评分
-
查看全部评分
|