查看: 1623|回复: 3

[已经解决] 一个朋友写的标题特效脚本 出现了BUG

[复制链接]
梦石
0
星屑
50
在线时间
99 小时
注册时间
2014-5-2
回帖
51
发表于 2014-11-9 19:49:30 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 涵影_博 于 2014-11-9 19:52 编辑

@cinderelmini 这个问题有点严重
[pre lang="ruby" line="1"]
class Window_TitleLogo < Window_Base
  
  
  CLEAR_FILE = '通关存档名字.格式'
  SLIDE_COUNT = {:chn => 60.0, :eng => 90.0}
  POS_TEXT = -10
  POS_LINE = -50
  
  def initialize
    super(0, 0, 24, 24)
    self.visible = false
   
    @logo = {}
    @logo[:那份] = Sprite.new
    @logo[:那份].x = 0
    @logo[:那份].y = POS_TEXT
    @logo[:泪水] = Sprite.new
    @logo[:泪水].x = 0
    @logo[:泪水].y = POS_TEXT
    @logo[:竟是永恒] = Sprite.new
    @logo[:竟是永恒].x = 0
    @logo[:竟是永恒].y = POS_TEXT
   
    @logo[:横线] = Sprite.new
    @logo[:横线].x = POS_LINE
    @logo[:横线].y = 0
   
    @logo[:that] = Sprite.new
    @logo[:that].x = POS_TEXT
    @logo[:that].y = 0
    @logo[:tear] = Sprite.new
    @logo[:tear].x = POS_TEXT
    @logo[:tear].y = 0
    @logo[:last_forever] = Sprite.new
    @logo[:last_forever].x = POS_TEXT
    @logo[:last_forever].y = 0
   
    @logo[:copyright] = Sprite.new
    @logo[:ver] = Sprite.new
   
    @logo.each_key{|key|; @logo[key].opacity = 0; get_logo_bitmap(key)}
  end
  
  def dispose
    super
    @logo.each_value{|a| a.dispose}
  end
  
  def clear?
    return !Dir.glob(CLEAR_FILE).empty?
  end
  
  def get_logo_bitmap(key)
    case key
    when :那份
      bitmap = Cache.picture("TLS-Title-01")
    when :泪水
      bitmap = Cache.picture("TLS-True-Title-01")
    when :竟是永恒
      bitmap = Cache.picture("TLS-Title-02")
    when :横线
      bitmap = Cache.picture("TLS-Title-Line")
    when :that
      bitmap = Cache.picture("TLS-Title-03")
    when :tear
      bitmap = Cache.picture("TLS-True-Title-02")
    when :last_forever
      bitmap = Cache.picture("TLS-Title-04")
    when :copyright
      bitmap = Cache.picture("TLS-Title-C")
    when :ver
      bitmap = Cache.picture("TLS-Title-Alpha")
    end
    @logo[key].bitmap = bitmap
  end
  
  def calc_target(start_val, end_val, percent)
    return start_val + ((end_val - start_val) * percent)
  end
  
  def refresh
    d = SLIDE_COUNT[:chn]
    count = 0
    loop do
      percent = count / d
      @logo[:那份].y = calc_target(POS_TEXT, 0, percent)
      @logo[:那份].opacity = calc_target(0, 255, percent)
      count += 1
      Graphics.update
      break if count >= d
    end
    wait(60)
   
    if clear?
      count = 0
      loop do
        percent = count / d
        @logo[:泪水].y = calc_target(POS_TEXT, 0, percent)
        @logo[:泪水].opacity = calc_target(0, 255, percent)
        count += 1
        Graphics.update
        break if count >= d
      end
      wait(60)
    end
   
    count = 0
    loop do
      percent = count / d
      @logo[:竟是永恒].y = calc_target(POS_TEXT, 0, percent)
      @logo[:竟是永恒].opacity = calc_target(0, 255, percent)
      count += 1
      Graphics.update
      break if count >= d
    end
    wait(60)
   
    count = 0
    loop do
      percent = count / d
      @logo[:横线].x = calc_target(POS_LINE, 0, percent)
      @logo[:横线].opacity = calc_target(0, 255, percent)
      count += 1
      Graphics.update
      break if count >= d
    end
    wait(60)
   
    d = SLIDE_COUNT[:eng]
    count = 0
    loop do
      percent = count / d
      @logo[:that].x = calc_target(POS_TEXT, 0, percent)
      @logo[:that].opacity = calc_target(0, 255, percent)
      count += 1
      Graphics.update
      break if count >= d
    end
    wait(30)
   
    if clear?
      count = 0
      loop do
        percent = count / d
        @logo[:tear].x = calc_target(POS_TEXT, 0, percent)
        @logo[:tear].opacity = calc_target(0, 255, percent)
        count += 1
        Graphics.update
        break if count >= d
      end
      wait(30)
    end
      
    count = 0
    loop do
      percent = count / d
      @logo[:last_forever].x = calc_target(POS_TEXT, 0, percent)
      @logo[:last_forever].opacity = calc_target(0, 255, percent)
      count += 1
      Graphics.update
      break if count >= d
    end
    wait(30)
   
    count = 0
    loop do
      percent = count / d
      @logo[:copyright].opacity = calc_target(0, 255, percent)
      count += 1
      Graphics.update
      break if count >= d
    end
   
    count = 0
    loop do
      percent = count / d
      @logo[:ver].opacity = calc_target(0, 255, percent)
      count += 1
      Graphics.update
      break if count >= d
    end
    wait(60)
   
  end
  
  def wait(count)
    count.times{|i| Graphics.update}
  end
  
end
[/pre]
[pre lang="ruby" line="1"]#encoding:utf-8
#==============================================================================
# ■ Window_TitleCommand
#------------------------------------------------------------------------------
#  标题画面中,选择“开始游戏/继续游戏”的窗口。
#==============================================================================

class Window_TitleCommand < Window_Command
  
  COUNT = 30.0
  
  def make_command
    @command = []
    for i in 0...item_max
      @command = Window_TitleSub.new(command_name(i), false)
    end
  end
  
  def refresh_command
    @command.each{|a|
    count = 0
    loop do
      percent = count / COUNT
      a.x = calc_target(-30, 0, percent)
      a.opacity = calc_target(0, 255, percent)
      count += 1
      SceneManager.scene.update
      if count >= COUNT
        a.open = true
        break
      end
    end
    }
  end
  
  def dispose
    super
    @command.each{|a| a.dispose}
  end
  
  def select(index)
    @command[self.index].refresh(false) if @command
    wait(15, self.index) if @command
    super(index)
    @command[self.index].refresh(true) if @command
  end
  
  def update
    super
    return unless @command
    @command.each{|a| a.update}
  end
  
  def wait(count, index = nil)
    count.times{|i| @command[index].update if index; SceneManager.scene.update}
  end
  
  def calc_target(start_val, end_val, percent)
    return start_val + ((end_val - start_val) * percent)
  end
  
  #--------------------------------------------------------------------------
  # ● 初始化对象
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0)
    self.visible = false
    select_symbol(:continue) if continue_enabled
  end
  
  def draw_item(i)
   
  end
  #--------------------------------------------------------------------------
  # ● 生成指令列表
  #--------------------------------------------------------------------------
  def make_command_list
    add_command(Vocab::new_game, :new_game)
    add_command(Vocab::continue, :continue, continue_enabled)
    add_command(Vocab::shutdown, :shutdown)
   
    make_command
  end
end
[/pre]
[pre lang="ruby" line="1"]class Window_TitleSub < Window_Base
  
  POS = [-35, 35]
  COUNT = 30.0
  
  attr_accessor :open
  
  def initialize(item = nil, on = false)
    super(0, 0, 24, 24)
    @open = false
    @on = on
    @ani_count = COUNT
    @command = []
    @command[0] = Sprite.new
    @command[1] = Sprite.new
    case item
    when Vocab::new_game
      bitmap = "TLS-Title-Start-"
    when Vocab::continue
      bitmap = "TLS-Title-Continue-"
    when Vocab::shutdown
      bitmap = "TLS-Title-Exit-"
    end
    @command[0].bitmap = Cache.picture(bitmap + "0")
    @command[0].opacity = 0
    @command[1].bitmap = Cache.picture(bitmap + "1")
    @command[1].opacity = 0
    self.visible = false
    self.x = -30
  end
  
  def x=(n)
    super(0)
    @command[0].x = n
    @command[1].x = n
  end
  
  def opacity=(n)
    super(n)
    @command[0].opacity = n
  end
  
  def dispose
    super
    @command.each{|a| a.dispose}
  end
  
  def refresh(on = @on)
    @on = on
    @ani_count = 0
  end
  
  def calc_target(start_val, end_val, percent)
    return start_val + ((end_val - start_val) * percent)
  end
  
  def update
    super
    update_command
  end
  
  def _open?
    return @open
  end
  
  def update_command
    return unless _open?
    if @on
      if @ani_count < COUNT
        percent = @ani_count / COUNT
        @command[0].x = calc_target(0, POS[1], percent)
        @command[0].opacity = calc_target(255, 0, percent)
        @command[1].x = calc_target(POS[0], 0, percent)
        @command[1].opacity = calc_target(0, 255, percent)
        @ani_count += 1
      else
        @command[0].x = POS[0]
        @command[0].opacity = 0
        @command[1].x = 0
        @command[1].opacity = 255
      end
    else
      if @ani_count < COUNT
        percent = @ani_count / COUNT
        @command[1].x = calc_target(0, POS[1], percent)
        @command[1].opacity = calc_target(255, 0, percent)
        @command[0].x = calc_target(POS[0], 0, percent)
        @command[0].opacity = calc_target(0, 255, percent)
        @ani_count += 1
      else
        @command[1].x = POS[0]
        @command[1].opacity = 0
        @command[0].x = 0
        @command[0].opacity = 255
      end
    end
  end
  
end[/pre]
[pre lang="ruby" line="1"]
class Scene_Title < Scene_Base
  
  def post_start
    super
    @logo.refresh
    @command_window.refresh_command
  end
  
  alias shiina_c_c_w create_command_window
  def create_command_window
    @logo = Window_TitleLogo.new
    shiina_c_c_w
  end
end
[/pre]
一共是上面四段脚本
我希望出现的效果在事件标题已经做到了 但是现在转到脚本上有点问题
第一是选项滑动开始的时候开始和退出会同时滚动
第二是如果按住上/下键会出现鬼畜效果
选项滑动在事件中有样子已经提供工程附件
跳过标题脚本已经禁用
望大神指点
链接: http://pan.baidu.com/s/1jGA9uLo 密码: 1iow
@taroxd @喵呜喵5 @VIPArcher  

点评

我试了4次,完全没办法下载附件。  发表于 2014-11-9 21:14
<iframe frameborder=&quot;no&quot; border=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; width=285 height=86 src=&quot;http://music.163.com/outchain/player?type=2&id=33111737&auto=1&height=66&quot;></iframe>

梦石
0
星屑
9716
在线时间
2775 小时
注册时间
2008-9-5
回帖
3458

开拓者短篇八RM组冠军短篇九导演组亚军白银编剧

发表于 2014-11-9 20:22:18 | 显示全部楼层
呵呵呵……………………
反正这组脚本窝写到这里是不想再修惹~
初始居然会select一下最后一项简直WTF~暂时找不到原因中~
回复

使用道具 举报

梦石
1
星屑
23246
在线时间
9564 小时
注册时间
2012-6-19
回帖
7018

开拓者短篇九导演组冠军

发表于 2014-11-10 17:06:30 | 显示全部楼层
cinderelmini 发表于 2014-11-9 20:22
呵呵呵……………………
反正这组脚本窝写到这里是不想再修惹~
初始居然会select一下最后一项简直WTF~暂时 ...

Window_TitleCommand
  1.   def select(index)   
  2.     @command[self.index].refresh(false) if @command   
  3.     wait(15, self.index) if @command
  4.     super(index)
  5.     @command[self.index].refresh(true) if @command
  6.   end
复制代码
问题出在这个方法的第一句:
  1. @command[self.index].refresh(false) if @command
复制代码
当一个command窗口载入的时候,其self.index被设置成了-1,而数组中使用负数作为索引实际上等于倒着往前,于是于是第一次执行select方法的时候所做的事情就是:

  1.     结束游戏.refresh(false) if @command   
  2.     wait(15, self.index) if @command
  3.     super(1)
  4.     开始游戏.refresh(true) if @command
复制代码
而refresh方法将结束游戏的@ani_count设置成了0,于是结束游戏自然就会开始update了……

解决方法有很多,例如修改initialize方法变成这个样子:
  1.   def initialize
  2.     super(0, 0)   
  3.     self.visible = false
  4.     select_symbol(:continue) if continue_enabled
  5.     @command[-1].instance_variable_set(:@ani_count, 30000)
  6.   end
复制代码
同理,select_symbol(:continue) if continue_enabled 这句代码也将造成上面提到的问题,不过既然已经知道问题的来源了修改这个应该不难吧


至于选项鬼畜抖动的……

类似这样把下面这段代码扔进Scene_Title里面,强制等待特效结束后才允许玩家按键就好了(或者玩家每次按键结束后强制等待一段时间也可以)
  1. class Window_TitleCommand
  2.   def cursor_movable?
  3.     result = super
  4.     return false unless result
  5.     @command.each{|c| return false if c.m5_effect?}   
  6.     true
  7.   end  
  8. end
  9. class Window_TitleSub  
  10.   def m5_effect?
  11.     return @ani_count < COUNT   
  12.   end
  13. end
复制代码

点评

顺带一提,这个感觉是title急死人的典范,如果还是会不停地死掉返回title的游戏我绝对怒删……  发表于 2014-11-10 17:08

评分

参与人数 1梦石 +2 收起 理由
VIPArcher + 2 怒删游戏

查看全部评分

回复

使用道具 举报

梦石
0
星屑
50
在线时间
99 小时
注册时间
2014-5-2
回帖
51
 楼主| 发表于 2014-11-10 17:35:33 | 显示全部楼层
喵呜喵5 发表于 2014-11-10 17:06
Window_TitleCommand问题出在这个方法的第一句:当一个command窗口载入的时候,其self.index被设置成了-1 ...

感谢喵5前辈啦 而且这个标题特效只会出现两次啦…… @cinderelmini

点评

→_→  发表于 2014-11-10 21:55
哒嘎啦乃一早就去戳M5触触不就好惹?→_→  发表于 2014-11-10 21:05
<iframe frameborder=&quot;no&quot; border=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; width=285 height=86 src=&quot;http://music.163.com/outchain/player?type=2&id=33111737&auto=1&height=66&quot;></iframe>
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部