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

Project1

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

[已经解决] 怎样在Window里调用self.dispose呢???

[复制链接]

Lv5.捕梦者

梦石
0
星屑
24302
在线时间
5050 小时
注册时间
2016-3-8
帖子
1618
跳转到指定楼层
1
发表于 2021-3-9 10:40:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
77星屑
本帖最后由 alexncf125 于 2021-3-9 10:48 编辑

这个显示弹幕的脚本可以在149行当@over为true时调用close(self.dispose)
显示弹幕的脚本

那为什么下方这个脚本不能在77-78行或81-82行间插句self.dispose if @show_count == 0呢,
插了的话, 123号变量为1时, 会在场所移动后一两秒(应该是@show_count == 0)时报错disposed window
RUBY 代码复制
  1. # encoding: utf-8
  2. #==============================================================================
  3. # ** Window_MapNamePlus
  4. #------------------------------------------------------------------------------
  5. #  This window displays the map name.
  6. #------------------------------------------------------------------------------
  7. #  使用方法:
  8. #    新建脚本页,复制粘贴
  9. #    在“Scene_Map”中找到“Window_MapName.new”,改成"Window_MapNamePlus.new"(大概在
  10. #     159行左右)
  11. #    在地图属性的设置窗口,“显示名称”中的地图名格式:“中文名@EnglishName”,即用“@”分割中文
  12. #     和英文地图名
  13. #==============================================================================
  14.  
  15. class Window_MapNamePlus < Window_Base
  16.   #--------------------------------------------------------------------------
  17.   # * Settings
  18.   #--------------------------------------------------------------------------
  19.   FONT_NAME_CH = ["PMingLiU", "FangSong"]       # Chinese Font Name
  20.   FONT_SIZE_CH = 42                             # Chinese Font Size
  21.   FONT_NAME_EN = ["Monotype Corsiva"]           # English Font Name
  22.   FONT_SIZE_EN = 28                             # English Font Size
  23.   FONT_BOLD    = false                          # True if Font in Bold
  24.   FONT_COLOR   = Color.new(255, 255, 255, 255)  # Color of Font
  25.   FONT_OUT     = true                           # True if Font Has Outline
  26.   OUT_COLOR    = Color.new(0, 0, 0, 200)        # Color of Outline Color of Font
  27.   FONT_SHADOW  = false                          # True if Text Drops Shadow
  28.   MODIFIER     = "~"                            # Modifier Added beside Map Name
  29.   PADDING      = 8                              # Padding between Window's Frame and Contents
  30.   LINE_HEIGHT  = 6                              # Height of Split Line
  31.   #--------------------------------------------------------------------------
  32.   # * Public Instance Variables
  33.   #--------------------------------------------------------------------------
  34.   attr_reader :map_name_ch                      # Chinese Map Name
  35.   attr_reader :map_name_en                      # English Map Name
  36.   attr_reader :line_x                           # Split Line X Coordinate
  37.   attr_reader :line_y                           # Split Line Y Coordinate
  38.   #--------------------------------------------------------------------------
  39.   # * Object Initialization
  40.   #--------------------------------------------------------------------------
  41.   def initialize
  42.     #----------------------------------------------------------------------
  43.     # * Set the window in the middle of screen.
  44.     #----------------------------------------------------------------------
  45.     super(((Graphics.width - window_width) / 2),
  46.       ((Graphics.height - (FONT_SIZE_CH + FONT_SIZE_EN + PADDING * 4 + LINE_HEIGHT)) / 2),
  47.       window_width, FONT_SIZE_CH + FONT_SIZE_EN + PADDING * 4 + LINE_HEIGHT)
  48.     #----------------------------------------------------------------------
  49.     # * Custom font and style.
  50.     #----------------------------------------------------------------------
  51.     contents.font.bold      = FONT_BOLD
  52.     contents.font.color     = FONT_COLOR
  53.     contents.font.outline   = FONT_OUT
  54.     contents.font.out_color = OUT_COLOR
  55.     contents.font.shadow    = FONT_SHADOW
  56.     #----------------------------------------------------------------------
  57.     # * Set Window Opacity
  58.     #----------------------------------------------------------------------
  59.     self.opacity = 0
  60.     self.contents_opacity = 0
  61.     @show_count = 0
  62.     refresh
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # * Get Window Width
  66.   #--------------------------------------------------------------------------
  67.   def window_width
  68.     return Graphics.width
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # * Frame Update
  72.   #--------------------------------------------------------------------------
  73.   def update
  74.     super
  75.     if @show_count > 0 && $game_map.name_display
  76.       update_fadein
  77.       @show_count -= 1
  78.     else
  79.       update_fadeout
  80.     end
  81.     @show_count = 0 unless $game_map.name_display##########
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # * Update Fadein
  85.   #--------------------------------------------------------------------------
  86.   def update_fadein
  87.     self.contents_opacity += 16
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # * Update Fadeout
  91.   #--------------------------------------------------------------------------
  92.   def update_fadeout
  93.     self.contents_opacity -= 16
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # * Open Window
  97.   #--------------------------------------------------------------------------
  98.   def open
  99.     refresh
  100.     @show_count = 150
  101.     self.contents_opacity = 0
  102.     self
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # * Close Window
  106.   #--------------------------------------------------------------------------
  107.   def close
  108.     @show_count = 0
  109.     self
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # * Refresh
  113.   #--------------------------------------------------------------------------
  114.   def refresh
  115.     contents.clear
  116.     set_map_name
  117.     unless $game_map.display_name.empty?
  118.       draw_map_name
  119.     end
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # * Draw Line
  123.   #--------------------------------------------------------------------------
  124.   def draw_line(rect)
  125.     temp_rect = rect.clone
  126.     temp_rect.height = LINE_HEIGHT
  127.     temp_rect.width /= 4
  128.     contents.gradient_fill_rect(temp_rect, color2, color1)
  129.     temp_rect.x += temp_rect.width
  130.     temp_rect.width *= 2
  131.     contents.fill_rect(temp_rect, color1)
  132.     temp_rect.x += temp_rect.width
  133.     temp_rect.width /= 2
  134.     contents.gradient_fill_rect(temp_rect, color1, color2)
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # * Set Map Name
  138.   #--------------------------------------------------------------------------
  139.   def set_map_name
  140. #~     temp_map_name = $game_map.display_name.split("@")
  141. #~     @map_name_ch  = temp_map_name[0].to_s
  142. #~     @map_name_en  = MODIFIER + " " + temp_map_name[1].to_s + " " + MODIFIER
  143.     ##########
  144.     @map_name_ch  = nil ; @map_name_en  = nil
  145.     $game_map.note.scan(/<第一行:(.*)>/){|matched|@map_name_cn = matched[0]}
  146.     @map_name_ch  = @map_name_cn || $game_map.display_name
  147.     $game_map.note.scan(/<第二行:(.*)>/){|matched|@map_name_en = matched[0]}
  148.     @map_name_en  = MODIFIER + " " + (@map_name_en || "作者未填写地图简介") + " " + MODIFIER
  149.     ##########
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # * Draw Map Name
  153.   #--------------------------------------------------------------------------
  154.   def draw_map_name
  155.     set_line_position
  156.     set_line_width
  157.     temp_line_rect = Rect.new(@line_x, @line_y, set_line_width, LINE_HEIGHT)
  158.     draw_line(temp_line_rect)
  159.     temp_name_rect_ch = Rect.new(0, 0, contents.width, FONT_SIZE_CH)
  160.     contents.font.name = FONT_NAME_CH
  161.     contents.font.size = FONT_SIZE_CH
  162.     draw_text(temp_name_rect_ch, @map_name_ch, 1)
  163.     temp_name_rect_en = Rect.new(0, FONT_SIZE_CH, contents.width, FONT_SIZE_EN)
  164.     contents.font.size = FONT_SIZE_EN
  165.     contents.font.name = FONT_NAME_EN
  166.     draw_text(temp_name_rect_en, @map_name_en, 1)
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   # * Set Line Width
  170.   #--------------------------------------------------------------------------
  171.   def set_line_width
  172.     text_width_ch = text_size(@map_name_ch).width * 1.5
  173.     text_width_en = text_size(@map_name_en).width * 1.5
  174.     (text_width_ch >= text_width_en) ?
  175.       (text_width_ch) : (text_width_en)
  176.   end
  177.   #--------------------------------------------------------------------------
  178.   # * Set Line Position
  179.   #--------------------------------------------------------------------------
  180.   def set_line_position
  181.     @line_x = (contents.width - set_line_width) / 2
  182.     @line_y = (contents.height - LINE_HEIGHT) / 2
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # * Get Color 1
  186.   #--------------------------------------------------------------------------
  187.   def color1
  188.     Color.new(255, 255, 255, 255)
  189.   end
  190.   #--------------------------------------------------------------------------
  191.   # * Get Color 2
  192.   #--------------------------------------------------------------------------
  193.   def color2
  194.     Color.new(255, 255, 255, 0)
  195.   end
  196. end
  197.  
  198. ##########
  199. module MAPNAMEPLUS
  200.   VAR_ID = 123##########變量
  201. end
  202.  
  203. #==============================================================================
  204. # ** Game_Map
  205. #------------------------------------------------------------------------------
  206. #  This class handles maps. It includes scrolling and passage determination
  207. # functions. The instance of this class is referenced by $game_map.
  208. #==============================================================================
  209.  
  210. class Game_Map
  211.   #--------------------------------------------------------------------------
  212.   # * New method: note
  213.   #--------------------------------------------------------------------------
  214.   def note
  215.     @map ? @map.note : ""
  216.   end
  217. end
  218.  
  219. #encoding:utf-8
  220. #==============================================================================
  221. # ■ Window_MapName
  222. #------------------------------------------------------------------------------
  223. #  顯示地圖名稱的窗口。
  224. #==============================================================================
  225.  
  226. class Window_MapName < Window_Base
  227.   #--------------------------------------------------------------------------
  228.   # ● 打開窗口
  229.   #--------------------------------------------------------------------------
  230.   alias :window_mapname_open_map_name_plus :open
  231.   def open
  232.     return if $game_variables[MAPNAMEPLUS::VAR_ID] >= 2
  233.     window_mapname_open_map_name_plus
  234.   end
  235.   #--------------------------------------------------------------------------
  236.   # ● 關閉窗口
  237.   #--------------------------------------------------------------------------
  238.   alias :window_mapname_close_map_name_plus :close
  239.   def close
  240.     return if $game_variables[MAPNAMEPLUS::VAR_ID] >= 2
  241.     window_mapname_close_map_name_plus
  242.   end
  243. end
  244.  
  245. #encoding:utf-8
  246. #==============================================================================
  247. # ■ Scene_Map
  248. #------------------------------------------------------------------------------
  249. #  地圖畫面
  250. #==============================================================================
  251.  
  252. class Scene_Map < Scene_Base
  253.   #--------------------------------------------------------------------------
  254.   # ● 結束前處理
  255.   #--------------------------------------------------------------------------
  256.   alias :scene_map_pre_terminate_map_name_plus :pre_terminate
  257.   def pre_terminate
  258.     scene_map_pre_terminate_map_name_plus
  259.     @map_name_plus_window.dispose if @map_name_plus_window && !@map_name_plus_window.disposed?
  260.     @map_name_plus_window = nil
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # ● 場所移動前的處理
  264.   #--------------------------------------------------------------------------
  265.   alias :scene_map_pre_transfer_map_name_plus :pre_transfer
  266.   def pre_transfer
  267.     @map_name_plus_window.close if @map_name_plus_window
  268.     scene_map_pre_transfer_map_name_plus
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # ● 場所移動后的處理
  272.   #--------------------------------------------------------------------------
  273.   alias :scene_map_post_transfer_map_name_plus :post_transfer
  274.   def post_transfer
  275.     scene_map_post_transfer_map_name_plus
  276.     var_value = $game_variables[MAPNAMEPLUS::VAR_ID]
  277.     case var_value
  278.     when 1, 2
  279.       @map_name_plus_window = Window_MapNamePlus.new unless @map_name_plus_window
  280.     end
  281.     @map_name_plus_window.open if @map_name_plus_window
  282.   end
  283. end
  284. ##########

最佳答案

查看完整内容

不好意思,其实我忘了看第二个脚本( 你这个窗口是绑定在Scene里面的一个实例变量,不需要自己释放了 因为Scene_Base里面会统一更新、释放是窗口的实例变量 具体可以看类里面的 dispose_windows 这是一种元编程模式,默认的那些窗口也都没有再写额外的更新和释放 以及如果只是单纯想让它不再显示,推荐用 window 类继承下来的 hide 和 show 方法 如果想刷新内容,推荐不要用生成、释放的模式,而是用它的 refresh ...

Lv6.析梦学徒

老鹰

梦石
40
星屑
33417
在线时间
6553 小时
注册时间
2012-5-26
帖子
3178

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

2
发表于 2021-3-9 10:40:46 | 只看该作者
本帖最后由 百里_飞柳 于 2021-3-9 12:59 编辑
alexncf125 发表于 2021-3-9 11:43
============================================================

这句是指, 在Scene_Map的def update內加 ...


不好意思,其实我忘了看第二个脚本(

你这个窗口是绑定在Scene里面的一个实例变量,不需要自己释放了
因为Scene_Base里面会统一更新、释放是窗口的实例变量
具体可以看类里面的 dispose_windows

这是一种元编程模式,默认的那些窗口也都没有再写额外的更新和释放

以及如果只是单纯想让它不再显示,推荐用 window 类继承下来的 hide 和 show 方法
如果想刷新内容,推荐不要用生成、释放的模式,而是用它的 refresh
回复

使用道具 举报

Lv6.析梦学徒

老鹰

梦石
40
星屑
33417
在线时间
6553 小时
注册时间
2012-5-26
帖子
3178

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

3
发表于 2021-3-9 11:18:02 | 只看该作者
这个弹幕脚本吓到我了,怎会有如此暴力的直接指定只能生成三个数目的更新方式(

因为它在窗口更新前判断了下窗口是否被释放
如果被释放了,就不再更新,因此没有报错,即189行
  1. $window_biu[0].update if $window_biu[0] && !$window_biu[0].disposed?
复制代码


你也可以在你的窗口的update前面判断下是否被释放
要么在
  1. window.update if !window.disposed?
复制代码

要么在
  1. def update
  2.   return if disposed?
  3.   super
  4. end
复制代码

回复

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
24302
在线时间
5050 小时
注册时间
2016-3-8
帖子
1618
4
 楼主| 发表于 2021-3-9 11:43:36 | 只看该作者
本帖最后由 alexncf125 于 2021-3-9 11:45 编辑
百里_飞柳 发表于 2021-3-9 11:18
这个弹幕脚本吓到我了,怎会有如此暴力的直接指定只能生成三个数目的更新方式(

因为它在窗口更新前判断了 ...

============================================================
window.update if !window.disposed?

这句是指, 在Scene_Map的def update內加句
@map_name_plus_window.update if !@map_name_plus_window.disposed?么
好像没效喔
============================================================
    def update
      return if disposed?
      super
    end

这段是指, 把Window_MapNamePlus的def update改成这样子么
  1.   def update
  2.     return if disposed?##########
  3.     super
  4.     if @show_count > 0 && $game_map.name_display
  5.       update_fadein
  6.       @show_count -= 1
  7.       self.dispose if @show_count == 0##########
  8.     else
  9.       update_fadeout
  10.     end
  11.     @show_count = 0 unless $game_map.name_display##########
  12.   end
复制代码


不过这样子改会变成117行报错disposed window喔
如果在117行前加句return if disposed?又会到103行报错
难不成是得在每个方法前都得return if disposed?
回复

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
33188
在线时间
10491 小时
注册时间
2009-3-15
帖子
4756
5
发表于 2021-3-9 12:27:28 | 只看该作者
77-78

RUBY 代码复制
  1. self.dispose if @map_name_plus_window
回复

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
24302
在线时间
5050 小时
注册时间
2016-3-8
帖子
1618
6
 楼主| 发表于 2021-3-9 12:37:03 | 只看该作者
soulsaga 发表于 2021-3-9 12:27
77-78

self.dispose if @map_name_plus_window[/pre]


別开玩笑吧....
77-78行的位置在class Window_MapNamePlus, 哪有@map_name_plus_window
@map_name_plus_window是class Scene_Map中, Window_MapNamePlus的实例

点评

哦..没留意..  发表于 2021-3-9 13:29
回复

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
24302
在线时间
5050 小时
注册时间
2016-3-8
帖子
1618
7
 楼主| 发表于 2021-3-9 13:17:36 | 只看该作者
百里_飞柳 发表于 2021-3-9 12:57
不好意思,其实我忘了看第二个脚本(

你这个窗口是绑定在Scene里面的一个实例变量,不需要自己释放了


好吧...总括而言,
即是不能在class Window_MapNamePlus的def update写self.dispose
只能在class Scene_Map的def update写@map_name_plus_window.dispose
就是这样没错吧...那我还是乖乖去Scene_Map写好了...谢谢大佬

点评

因为scene会自动更新它里面的全部窗口,即 @window_xxx 这样形式的变量,如果是窗口类的对象,它自动帮你更新、释放,所以你再释放,就会出现报错  发表于 2021-3-9 14:06
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-28 19:27

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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