幻想森林

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1916|回复: 3

[RM2K&2K3] 这个脚本影响帧数,请教有什么优化或解决的办法

[复制链接]

40

主题

190

帖子

1635

积分

⑥精研

●~  ●~   ●

积分
1635
发表于 2009-12-11 13:38:16 | 显示全部楼层 |阅读模式
这个脚本的效果是当某开关打开,相应的事件闪烁不同的颜色,严重影响游戏帧数,症状是在游戏中进一下别的地图再回原地图,速度会变得很卡,帧数下降到11左右!但是这效果我又不想放弃,有什么优化的办法么?

  1. Goahead1_Color = [255,0,0] #颜色红色[R,G,B]
  2. Goahead1_Count = 20 # 闪烁间隔
  3. Goahead2_Color = [0,0,255] #颜色蓝色[R,G,B]
  4. Goahead2_Count = 20 # 闪烁间隔
  5. Goahead3_Color = [255,0,255] #颜色紫色[R,G,B]
  6. Goahead3_Count = 20 # 闪烁间隔
  7. Goahead4_Color = [0,255,0] #颜色绿色[R,G,B]
  8. Goahead4_Count = 20 # 闪烁间隔
  9. Goahead5_Color = [255,255,0] #颜色黄色[R,G,B]
  10. Goahead5_Count = 20 # 闪烁间隔
  11. Goahead6_Color = [0,255,255] #颜色浅蓝色[R,G,B]
  12. Goahead6_Count = 20 # 闪烁间隔
  13. class Sprite_Character < RPG::Sprite
  14.   #燃烧持续扣血
  15.   def update_tone1
  16.     @count ||= Goahead1_Count
  17.     if @count <= 0
  18.       @count = Goahead1_Count
  19.       for i in 1..20
  20.         if @character.moving? and @character.id == i and $game_switches[i+600] == true
  21.           name = $game_map.events[i].name
  22.           data = name.split(/,/)
  23.           data[1] = data[1].to_i - $game_variables[31] - 20
  24.           $game_map.events[i].name = data[0].to_s+","+data[1].to_s+","+data[2].to_s+","+data[3].to_s+","+data[4].to_s+","+data[5].to_s+","+data[6].to_s+","+data[7].to_s+","+data[8].to_s
  25.         end
  26.       end
  27.     else
  28.       @count -= 1
  29.     end
  30.     if @count < Goahead1_Count/2
  31.       self.tone.set(*Goahead1_Color)
  32.     else
  33.       self.tone.set(0,0,0,0)
  34.     end
  35.   end
  36.   #冰冻减慢速度
  37.   def update_tone2
  38.     @count ||= Goahead2_Count
  39.     if @count <= 0
  40.       @count = Goahead2_Count
  41.       for i in 1..20
  42.         if @character.moving? and @character.id == i and $game_switches[i+625] == true
  43.           $game_map.events[i].move_speed = 1
  44.         end
  45.       end
  46.     else
  47.       @count -= 1
  48.     end
  49.     if @count < Goahead2_Count/2
  50.       self.tone.set(*Goahead2_Color)
  51.     else
  52.       self.tone.set(0,0,0,0)
  53.     end
  54.   end
  55.   
  56.   #麻痹原地打转
  57.   def update_tone3
  58.     @count ||= Goahead3_Count
  59.     if @count <= 0
  60.       @count = Goahead3_Count
  61.       for i in 1..20
  62.         if @character.moving? and @character.id == i and $game_switches[i+650] == true
  63.           $game_map.events[i].move_speed = 0
  64.         end
  65.       end
  66.     else
  67.       @count -= 1
  68.     end
  69.     if @count < Goahead3_Count/2
  70.       self.tone.set(*Goahead3_Color)
  71.     else
  72.       self.tone.set(0,0,0,0)
  73.     end
  74.   end
  75.   
  76.   #中毒持续扣血
  77.   def update_tone4
  78.     @count ||= Goahead4_Count
  79.     if @count <= 0
  80.       @count = Goahead4_Count
  81.       for i in 1..20
  82.         if @character.moving? and @character.id == i and $game_switches[i+675] == true
  83.           name = $game_map.events[i].name
  84.           data = name.split(/,/)
  85.           data[1] = data[1].to_i - $game_variables[34]
  86.           $game_map.events[i].name = data[0].to_s+","+data[1].to_s+","+data[2].to_s+","+data[3].to_s+","+data[4].to_s+","+data[5].to_s+","+data[6].to_s+","+data[7].to_s+","+data[8].to_s
  87.         end
  88.       end
  89.     else
  90.       @count -= 1
  91.     end
  92.     if @count < Goahead4_Count/2
  93.       self.tone.set(*Goahead4_Color)
  94.     else
  95.       self.tone.set(0,0,0,0)
  96.     end
  97.   end
  98.   
  99.   
  100.   
  101.   
  102.   
  103.   alias goahead1_update update
  104.   def update
  105.     reset = true
  106.     for i in 1..20
  107.     if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+600] == true
  108.       update_tone1
  109.       reset = false
  110.     end
  111.     if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+625] == true
  112.       update_tone2
  113.       reset = false
  114.     end
  115.     if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+650] == true
  116.       update_tone3
  117.       reset = false
  118.     end
  119.     if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+675] == true
  120.       update_tone4
  121.       reset = false
  122.     end
  123.     if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+700] == true
  124.       update_tone5
  125.       reset = false
  126.     end
  127.     if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+725] == true
  128.       update_tone6
  129.       reset = false
  130.     end
  131.     self.tone.set(0, 0, 0) if reset
  132.     end
  133.     goahead1_update
  134.   end
  135. end
复制代码
回复

使用道具 举报

550

主题

9116

帖子

214748万

积分

超级版主

如同神一般的存在,腿神!拖后腿的神~~

Rank: 8Rank: 8

积分
2147483647
发表于 2009-12-11 14:38:57 | 显示全部楼层
如果你只是要闪耀的效果,就用显示动画+事件脚本比较好。。。纯属个人建议
我就是你们的神,庶民们,追随我吧!跟着我一起拖后腿!
回复 支持 反对

使用道具 举报

550

主题

9116

帖子

214748万

积分

超级版主

如同神一般的存在,腿神!拖后腿的神~~

Rank: 8Rank: 8

积分
2147483647
发表于 2009-12-11 14:57:53 | 显示全部楼层
alias goahead1_update update
  def update
    reset = true
    for i in 1..20
    if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+600] == true
      update_tone1
      reset = false
    end
    if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+625] == true
      update_tone2
      reset = false
    end
    if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+650] == true
      update_tone3
      reset = false
    end
    if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+675] == true
      update_tone4
      reset = false
    end
    if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+700] == true
      update_tone5
      reset = false
    end
    if @character.is_a?(Game_Event) and @character.id == i and $game_switches[i+725] == true
      update_tone6
      reset = false
    end
    self.tone.set(0, 0, 0) if reset
    end

写的太不理想了。。。长。。太长。。。我看不出来你的循环有什么用
  for i in 1..20
    if @character.id == i
这样的话 你完全可以 @character.id >0 &&@character.id < 21做判断的条件
而把循环删除
在这个基础上。。。reset = XXX完全无用
开头的 reset = true删
结尾处 return true 代替就可以
reset = false 改成 return false 不要再坐后面的无用功了直接返回就可以了
另外reset这个变量是干什么的。。。根本看不出来。。。
$game_switches[i+650] == true 再说这个。。。这才是你该用循环的地方
你的 []中是 i+626  i+650...反正后面是递加25
那么完全可以
for i in 0...n
   if $game_switches[@character_id+625 + 25 * i]
      XXXXXXX
  end
end
至于调用你的tone方法学一下alias。。
先说这么多。。。

再说前面的脚本。。恕我直言比后半段还乱。。。大体上问题都一样。。。

我说实话,这不知道是谁写的。。。冗长,效率低。。。建议重做。。。

以上个人建议。。。不喜勿喷,说一句不喜欢就可以了
我就是你们的神,庶民们,追随我吧!跟着我一起拖后腿!
回复 支持 反对

使用道具 举报

40

主题

190

帖子

1635

积分

⑥精研

●~  ●~   ●

积分
1635
 楼主| 发表于 2009-12-11 14:59:39 | 显示全部楼层
好吧,还是用动画做吧!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|幻想森林

GMT+8, 2024-4-16 21:39 , Processed in 0.019107 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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