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

Project1

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

[有事请教] 请教关于此脚本的优化方案

[复制链接]

Lv4.逐梦者

梦石
0
星屑
8498
在线时间
775 小时
注册时间
2017-11-10
帖子
1231
跳转到指定楼层
1
发表于 2019-5-1 11:48:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
RUBY 代码复制
  1. #==============================================================================
  2. # ■ Angel_Skill_Ex
  3. #==============================================================================
  4. module Angel_Skill_Ex
  5.   Use_Elements_Set = true #是否用屬性表示
  6.   Show_Elements = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] #表示的屬性
  7.   Elements_Icon = [0,2209, 2211, 2214, 2216, 2213, 2220, 2210, 2208,
  8.                   104, 105, 106, 107, 108, 109, 110, 111,128,129,130,131] #屬性的圖標
  9. end
  10. #==============================================================================
  11. # ■ Window_Skill_List
  12. #==============================================================================
  13. class Window_Skill_List < Window_Selectable
  14.   #--------------------------------------------------------------------------
  15.   # * 定義實例變量
  16.   #--------------------------------------------------------------------------
  17.   attr_accessor :info_window
  18.   #--------------------------------------------------------------------------
  19.   # ● 初始化對象
  20.   #     actor  : 角色
  21.   #--------------------------------------------------------------------------
  22.   def initialize(actor, h=416-(WLH+32))
  23.     super(0, WLH+56, 280, h-24)
  24.     @actor = actor
  25.     @column_max = 1
  26.     self.index = 0
  27.     @info_window = nil
  28.     data_refresh
  29.     update_cursor
  30.   end
  31.   #--------------------------------------------------------------------------
  32.   # ● 獲取技能
  33.   #--------------------------------------------------------------------------
  34.   def skill
  35.     return @data[self.index]
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # ● 數據刷新
  39.   #--------------------------------------------------------------------------
  40.   def data_refresh
  41.     @data = []
  42.     for skill in @actor.skills
  43.       @data.push(skill)
  44.       if skill.id == @actor.last_skill_id
  45.         self.index = @data.size - 1
  46.       end
  47.     end
  48.     @item_max = @data.size
  49.     create_contents
  50.     refresh
  51.   end
  52.   #--------------------------------------------------------------------------
  53.   # ● 刷新
  54.   #--------------------------------------------------------------------------
  55.   def refresh
  56.     self.contents.clear
  57.     for i in 0...@item_max
  58.       draw_item(i, false)
  59.     end
  60.   end
  61.   #--------------------------------------------------------------------------
  62.   # ● 描繪技能
  63.   #    index : 索引
  64.   #--------------------------------------------------------------------------
  65.   def draw_item(index, clear=true)
  66.     rect = item_rect(index)
  67.     self.contents.clear_rect(rect) if clear
  68.     skill = @data[index]
  69.     if skill != nil
  70.       rect.width -= 4
  71.       enabled = @actor.skill_can_use?(skill)
  72.       draw_item_name(skill, rect.x, rect.y, enabled)
  73.       if !enabled
  74.       self.contents.font.color = knockout_color
  75.       self.contents.draw_text(rect.x + 160, rect.y, 160, WLH, "無法使用")
  76.       end
  77.     end
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * 更新動態説明視窗內容資訊
  81.   #--------------------------------------------------------------------------
  82.   def update_help
  83.     @help_window.set_text(skill == nil ? "無技能" : skill.description)
  84.     @info_window.refresh(skill) unless @info_window.nil?
  85.   end
  86. end
  87. #==============================================================================
  88. # ■ Window_Skill_Info
  89. #==============================================================================
  90. class Window_Skill_Info < Window_Base
  91.   #--------------------------------------------------------------------------
  92.   # ● 初始化對象
  93.   #--------------------------------------------------------------------------
  94.   def initialize(y=WLH*5+96, h=416-(WLH*5+96))
  95.     super(280, y, 264, h)
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● 常量
  99.   #--------------------------------------------------------------------------
  100.   SCOPE = ["無", "敵單體", "敵全體", "敵單體連擊",
  101.            "特別目標", "敵二體", "敵三體", "我方單體",
  102.            "我方全體", "我方瀕死単體", "我方瀕死全體", "自身"]
  103.   #--------------------------------------------------------------------------
  104.   # ● 刷新
  105.   #--------------------------------------------------------------------------
  106.   def refresh(skill=nil)
  107.     self.contents.clear
  108.     return if skill.nil?
  109.     self.contents.font.color = system_color
  110.     self.contents.draw_text(0, WLH*0, 100, WLH, "類別")
  111.     self.contents.draw_text(0, WLH*1, 100, WLH, "效果範圍")
  112.     self.contents.draw_text(0, WLH*2, 100, WLH, "追加傷害")
  113.     self.contents.draw_text(0, WLH*3, 100, WLH, "命中率")
  114.     self.contents.draw_text(0, WLH*4, 100, WLH, "屬性") if Angel_Skill_Ex::Use_Elements_Set
  115.     self.contents.draw_text(0, WLH*5, 100, WLH, "活力消耗")
  116.     self.contents.draw_text(0, WLH*6, 100, WLH, "速度修正")
  117.     self.contents.font.color = normal_color
  118.     if skill.base_damage > 0
  119.       txt = skill.physical_attack ? "物理攻撃" : "攻撃魔法"
  120.     elsif skill.base_damage < 0
  121.       txt = skill.physical_attack ? "回復技能" : "回復魔法"
  122.     elsif skill.hit < 1
  123.       txt = skill.physical_attack ? "被動技能" : "被動技能"
  124.     else
  125.       txt = skill.physical_attack ? "特殊技能" : "輔助魔法"
  126.     end
  127.     self.contents.draw_text(120, WLH*0, 160, WLH, txt)
  128.     self.contents.draw_text(120, WLH*1, 216, WLH, SCOPE[skill.scope])
  129.     self.contents.draw_text(120, WLH*2, 60, WLH, skill.base_damage.to_s+" 點", 2)
  130.     self.contents.draw_text(120, WLH*3, 60, WLH, skill.hit.to_s+" %", 2)
  131.     self.contents.draw_text(120, WLH*5, 60, WLH, skill.mp_cost.to_s+" 點", 2)
  132.     self.contents.draw_text(120, WLH*6, 60, WLH, skill.speed.to_s+" %", 2)
  133.     if Angel_Skill_Ex::Use_Elements_Set
  134.       i = 0
  135.       for element_id in skill.element_set
  136.         next unless Angel_Skill_Ex::Show_Elements.include?(element_id)
  137.         draw_element_icon(element_id, 120+i*24, WLH*4)
  138.         i += 1
  139.       end
  140.     end
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # ● 屬性圖標的描繪
  144.   #--------------------------------------------------------------------------
  145.   def draw_element_icon(element_id, x, y, enabled = true)
  146.     draw_icon(Angel_Skill_Ex::Elements_Icon[element_id], x, y, enabled)
  147.   end
  148. end
  149. #==============================================================================
  150. # ■ Window_Skill_User
  151. #==============================================================================
  152. class Window_Skill_User < Window_Base
  153.   #--------------------------------------------------------------------------
  154.   # ● 初始化對象
  155.   #    actor : 角色
  156.   #--------------------------------------------------------------------------
  157.   def initialize(actor)
  158.     super(280, WLH+56, 264, WLH*6 - 8)
  159.     @actor = actor
  160.     refresh
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # ● 刷新
  164.   #--------------------------------------------------------------------------
  165.   def refresh
  166.     self.contents.clear
  167.     draw_actor_face(@actor, 0, 0)
  168.     draw_actor_graphic(@actor, 200, WLH*1+24)
  169.     draw_actor_name(@actor, 104, 0)
  170.     draw_actor_state(@actor, 104, WLH*1)
  171.     draw_actor_hp(@actor, 104, WLH*2)
  172.     draw_actor_mp(@actor, 104, WLH*3)
  173.   end
  174. end
  175. #==============================================================================
  176. # ■ Window_Skill_Help
  177. #==============================================================================
  178. class Window_Skill_Help < Window_Base
  179.   Wait_time = 40
  180.   Fade_out = Wait_time / 4
  181.   def xx(w)
  182.     return (544-w)/2
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # * 初始化參數
  186.   #--------------------------------------------------------------------------
  187.   def initialize
  188.     super(xx(240), 160, 240, WLH+32)
  189.     @wait = 0
  190.     self.z = 600
  191.     self.visible = false
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # * 設置文字
  195.   #--------------------------------------------------------------------------
  196.   def set_text(type)
  197.     case type
  198.     when 0
  199.     text = "該技能魔法使用的時機不對哦。"
  200.     when 1
  201.     text = "該技能魔法暫時不能起效果。"
  202.     when 2
  203.     text = "該角色的活力值不夠了。"
  204.     when 3
  205.     text = "無效技能!"
  206.     else
  207.     return
  208.     end
  209.     w = self.contents.text_size(text).width
  210.     self.width = w + 32
  211.     self.x = xx(self.width)
  212.     self.contents.dispose
  213.     self.contents = Bitmap.new(w, WLH)
  214.     self.contents.draw_text(0, 0, w, WLH, text)
  215.     @wait = Wait_time
  216.     self.visible = true
  217.     self.opacity = self.contents_opacity = 255
  218.   end
  219.   #--------------------------------------------------------------------------
  220.   # * 畫面更新
  221.   #--------------------------------------------------------------------------
  222.   def update
  223.     super
  224.     @wait -= 1
  225.     if @wait < Fade_out
  226.       self.opacity = self.contents_opacity = 255 / Fade_out * @wait
  227.       self.visible = false if @wait == 0
  228.     end
  229.   end
  230. end
  231. #==============================================================================
  232. # ■ Scene_Skill
  233. #==============================================================================
  234. class Scene_Skill < Scene_Base
  235.   #--------------------------------------------------------------------------
  236.   # ● 物件初始化
  237.   #     actor_index : 主角編號
  238.   #--------------------------------------------------------------------------
  239.   def initialize(actor_index = 0)
  240.     @actor_index = actor_index
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # * 程序開始
  244.   #--------------------------------------------------------------------------
  245.   def start
  246.     super
  247.     create_menu_background
  248.     @actor = $game_party.members[@actor_index]
  249.     @viewport = Viewport.new(0, 0, 544, 416)
  250.     @help_window = Window_Help.new
  251.     @help_window.viewport = @viewport
  252.     @status_window = Window_Skill_User.new(@actor)
  253.     @status_window.viewport = @viewport
  254.     @skill_info_window = Window_Skill_Info.new
  255.     @skill_info_window.viewport = @viewport
  256.     @skill_window = Window_Skill_List.new(@actor)
  257.     @skill_window.viewport = @viewport
  258.     @skill_window.info_window = @skill_info_window
  259.     @skill_window.help_window = @help_window
  260.     @target_window = Window_MenuStatus.new(0, 0)
  261.     @message_window  = Window_Skill_Help.new
  262.     hide_target_window
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # * 程序終止
  266.   #--------------------------------------------------------------------------
  267.   def terminate
  268.     super
  269.     dispose_menu_background
  270.     @help_window.dispose
  271.     @status_window.dispose
  272.     @skill_info_window.dispose
  273.     @skill_window.dispose
  274.     @target_window.dispose
  275.     @message_window.dispose
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # * 更新幀
  279.   #--------------------------------------------------------------------------
  280.   alias angel_skill_update update
  281.   def update
  282.   angel_skill_update
  283.   if @message_window.visible
  284.      @message_window.update
  285.      return
  286.   end
  287. end
  288.   #--------------------------------------------------------------------------
  289.   # * 更新技能選擇指令輸入資訊
  290.   #--------------------------------------------------------------------------
  291.   def update_skill_selection
  292.     if Input.trigger?(Input::B)
  293.       Sound.play_cancel
  294.       return_scene
  295.     elsif Input.trigger?(Input::R)
  296.       Sound.play_cursor
  297.       next_actor
  298.     elsif Input.trigger?(Input::L)
  299.       Sound.play_cursor
  300.       prev_actor
  301.     elsif Input.trigger?(Input::C)
  302.       @skill = @skill_window.skill
  303.       if @skill != nil
  304.         @actor.last_skill_id = @skill.id
  305.       else
  306.         Sound.play_buzzer
  307.         @message_window.set_text(3)
  308.        return
  309.      end
  310.  
  311.       if @actor.skill_can_use?(@skill)
  312.         Sound.play_decision
  313.         determine_skill
  314.       elsif @actor.calc_mp_cost(@skill) > @actor.mp
  315.         Sound.play_buzzer
  316.         @message_window.set_text(2)
  317.       else
  318.         Sound.play_buzzer
  319.         @message_window.set_text(0)
  320.       end
  321.  
  322.     end
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   # * 更新目標選擇指令輸入資訊
  326.   #--------------------------------------------------------------------------
  327.   def update_target_selection
  328.     if Input.trigger?(Input::B)
  329.       Sound.play_cancel
  330.       hide_target_window
  331.     elsif Input.trigger?(Input::C)
  332.       if !@actor.skill_can_use?(@skill)
  333.         Sound.play_buzzer
  334.         @message_window.set_text(2)
  335.       else
  336.         determine_target
  337.       end
  338.     end
  339.   end
  340.   #--------------------------------------------------------------------------
  341.   # * 判定技能是否可以施用於目標
  342.   #    若無效(如施用增加HP的技能於瀕死者),播放“無效”SE。
  343.   #--------------------------------------------------------------------------
  344.   def determine_target
  345.     used = false
  346.     if @skill.for_all?
  347.       for target in $game_party.members
  348.         target.skill_effect(@actor, @skill)
  349.         used = true unless target.skipped
  350.       end
  351.     elsif @skill.for_user?
  352.       target = $game_party.members[@target_window.index - 100]
  353.       target.skill_effect(@actor, @skill)
  354.       used = true unless target.skipped
  355.     else
  356.       $game_party.last_target_index = @target_window.index
  357.       target = $game_party.members[@target_window.index]
  358.       target.skill_effect(@actor, @skill)
  359.       used = true unless target.skipped
  360.     end
  361.     if used
  362.       use_skill_nontarget
  363.     else
  364.       Sound.play_buzzer
  365.       @message_window.set_text(1)
  366.     end
  367.   end
  368. end
  369. #==============================================================================
  370. # ** Scene_Battle
  371. #------------------------------------------------------------------------------
  372. #  這個類用來執行顯示作戰畫面的程式。
  373. #==============================================================================
  374. class Scene_Battle < Scene_Base
  375.   #--------------------------------------------------------------------------
  376.   # ● 開始接收技能選擇的指令輸入資訊
  377.   #--------------------------------------------------------------------------
  378.   def start_skill_selection
  379.     @help_window = Window_Help.new
  380.     @skill_window = Window_Skill_List.new(@active_battler, 232)
  381.     @skill_info_window = Window_Skill_Info.new(80, 208)
  382.     @skill_window.info_window = @skill_info_window
  383.     @skill_window.help_window = @help_window
  384.     @actor_command_window.active = false
  385.   end
  386.   #--------------------------------------------------------------------------
  387.   # ● 停止接收技能選擇的指令輸入資訊
  388.   #--------------------------------------------------------------------------
  389.   def end_skill_selection
  390.    if @skill_window != nil
  391.       @skill_window.dispose
  392.       @skill_info_window.dispose
  393.       @skill_window = @skill_info_window = nil
  394.       @help_window.dispose
  395.       @help_window = nil
  396.     end
  397.     @actor_command_window.active = true
  398.   end
  399. end

请教为何描绘Window_Skill_Info里面的内容时会特别的卡顿
特别在技能很多的情况之下。
请教有没有其他描绘办法可以减少卡顿的现象?
一个只会简单事件的Rm新人,脚本完全不懂。只求做个简单的游戏完成自己的游戏之梦而已。
第一个游戏已经完成,等待各素材的完成和测试。

Lv5.捕梦者 (版主)

梦石
1
星屑
23963
在线时间
3338 小时
注册时间
2011-7-8
帖子
3925

开拓者

2
发表于 2019-5-1 14:29:35 | 只看该作者
有2点可以考虑:
1. 在技能不变的情况下跳过refresh,可以在scene里判定或者在window类里判定,这个是卡顿的主要原因
2. 对于一些位置和内容不变的文字内容,可以在window的initialize方法里建立一个sprite,其bitmap与contents等大的,把文字绘制在这里面。这样refresh时就无需重绘这部分文字。
熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
8498
在线时间
775 小时
注册时间
2017-11-10
帖子
1231
3
 楼主| 发表于 2019-5-2 19:32:37 | 只看该作者
guoxiaomi 发表于 2019-5-1 14:29
有2点可以考虑:
1. 在技能不变的情况下跳过refresh,可以在scene里判定或者在window类里判定,这个是卡顿的 ...

谢谢前辈
我采用了第一种。完美解决了卡顿的问题。
于是想问问第二种该怎么实现?
一个只会简单事件的Rm新人,脚本完全不懂。只求做个简单的游戏完成自己的游戏之梦而已。
第一个游戏已经完成,等待各素材的完成和测试。
回复 支持 反对

使用道具 举报

Lv5.捕梦者 (版主)

梦石
1
星屑
23963
在线时间
3338 小时
注册时间
2011-7-8
帖子
3925

开拓者

4
发表于 2019-5-2 20:51:19 | 只看该作者
本帖最后由 guoxiaomi 于 2019-5-2 20:53 编辑
文雅夕露 发表于 2019-5-2 19:32
谢谢前辈
我采用了第一种。完美解决了卡顿的问题。
于是想问问第二种该怎么实现?


VX不常用,大概类似这样的写法,不过一般没有明显的效率提升
RUBY 代码复制
  1. class Window_XXX < Window_Base
  2.   def initialize
  3.     # ...   
  4.     bitmap = Bitmap.new(self.width - 32, self.height - 32)
  5.     bitmap.draw_text( ... )
  6.     bitmap.blt( ... )
  7.     @sprite_static = Sprite.new
  8.     @sprite_static.bitmap = bitmap
  9.   end
  10.  
  11.   def dispose   
  12.     @sprite_static.dispose
  13.     # ...
  14.   end
  15. end
熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-26 04:04

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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