Project1

标题: (已解决)关于计时器的问题 [打印本页]

作者: alt236679    时间: 2019-1-18 22:57
标题: (已解决)关于计时器的问题
本帖最后由 alt236679 于 2019-1-28 19:31 编辑

感觉标题好绕orz那就点进来看一下吧↓

想在游戏里做一个全局计时器,并把这个定为了游戏的系统核心。但是系统默认的计时器不能在菜单画面计时。所以用了变量的值代替倒计时剩余秒数,然后在论坛随便找了个在画面上显示变量的脚本,就当是一个简易计时器了。
但是还有问题。计时器的值是不断刷新的没错,可是在对话和菜单界面时,显示的变量值不会刷新,在返回到地图后恢复正常。
(假如计时器的值为58,我进入菜单并停留10秒,此时画面上显示的值停留在58,再次按下退出键后,会一下子跳到48,然后继续倒计时)

作为一个只会改一点基础脚本的咸鱼orz还是有问题要来请教大家:
1.如果还是用变量版的自制计时器,如何实现在游戏内的任何地方都能正常显示并刷新计时器,by the way,我想让它更像系统默认的计时器样式
2.如果可以通过修改脚本,仍然得用系统的计时器,具体要如何修改
3.如果还有其他的方法……
4.……
【↑有点忘了自己还要问什么x】

那……暂时就这样吧x
寒假到了,祝大家填坑力upup

如果你要看那个 随便找的 显示变量代码的话……

作者: MCCF    时间: 2019-1-19 00:04
你这个窗口完全是定义在Scene_Map的,在其他地方自然不能生效。
以前做过一个很特殊的,就是直接定义在Scene_Base里。这样从理论上来说,在所有场景都会刷新。
要具体方法就回复我,找个时间弄一下。
作者: KB.Driver    时间: 2019-1-19 01:39
本帖最后由 KB.Driver 于 2019-1-19 01:43 编辑



所有Scene都加载计时器。

RUBY 代码复制
  1. class Scene_Base
  2.   #--------------------------------------------------------------------------
  3.   # ● 生成计时器
  4.   #--------------------------------------------------------------------------
  5.   alias start_for_timer start
  6.   def start
  7.     start_for_timer
  8.     if $game_timer && make_timer_scene?
  9.       @viewport99 = Viewport.new
  10.       @viewport99.z = 201
  11.       @timer_sprite = Sprite_Timer.new(@viewport99)
  12.     end
  13.   end
  14.   #--------------------------------------------------------------------------
  15.   # ● 消除计时器
  16.   #--------------------------------------------------------------------------
  17.   alias terminate_for_timer terminate
  18.   def terminate
  19.     terminate_for_timer
  20.     @timer_sprite.dispose if @timer_sprite
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # ● 更新计时器
  24.   #--------------------------------------------------------------------------
  25.   alias update_for_timer update
  26.   def update
  27.     update_for_timer
  28.     if @timer_sprite && make_timer_scene?
  29.       $game_timer.update
  30.       @timer_sprite.update
  31.     end
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● 是否需要添加计时器
  35.   #--------------------------------------------------------------------------
  36.   def make_timer_scene?
  37.     case SceneManager.scene.class
  38.     when Scene_Map,Scene_Battle then false
  39.     else true end
  40.   end
  41. end
  42.  
  43. class Scene_Title
  44.   #--------------------------------------------------------------------------
  45.   # ● 标题界面不弄计时器
  46.   #--------------------------------------------------------------------------
  47.   alias start_for_stop_timer start
  48.   def start
  49.     $game_timer.stop if $game_timer
  50.     start_for_stop_timer
  51.   end
  52. end

作者: alt236679    时间: 2019-1-19 20:49
本帖最后由 alt236679 于 2019-1-19 20:51 编辑
KB.Driver 发表于 2019-1-19 01:39
所有Scene都加载计时器。

class Scene_Base


测试了一下,有点小问题
我用了喵呜喵5的菜单子界面不隐藏选项窗口脚本,当我打开菜单时,计时器的显示是这样的。当我在27秒时打开菜单,计时器会有显示重复:
在子界面下恢复正常:


这是我在脚本中的设定(其实就是原本的设定吧!):




所以厚着脸皮来请教一下修改方案……

还有,想再问一下。如果说计时器结束后,我想要执行 退出游戏 的指令,那么如何保证在任何场景(当然也除了标题画面)下,计时结束后都能立即结束游戏?
作者: KB.Driver    时间: 2019-1-19 22:59


RUBY 代码复制
  1. #==============================================================================
  2. # ■ CLD99::Timer
  3. #------------------------------------------------------------------------------
  4. #  除了标题界面,所有界面都生效的计时器。
  5. #   在此进行计时器的设置。
  6. #==============================================================================
  7. module CLD99
  8.   module Timer
  9.  
  10.     SCENE_NO_TIMER = [Scene_Title,Scene_Gameover]
  11.     # 进入此场景,计时器将自动停止。
  12.     # 默认:[Scene_Title, Scene_Gameover]
  13.  
  14.     GAME_OVER_SWITCH = 0
  15.     # 计时器为0时立刻结束游戏?
  16.     # -1 禁止 0 允许 正整数 检查对应编号开关
  17.  
  18.   end
  19. end
  20.  
  21. #==============================================================================
  22. # ■ Scene_Base
  23. #------------------------------------------------------------------------------
  24. #  游戏中所有 Scene 类(场景类)的父类
  25. #==============================================================================
  26. class Scene_Base
  27.   #--------------------------------------------------------------------------
  28.   # ● 开始处理
  29.   #--------------------------------------------------------------------------
  30.   alias start_for_timer start
  31.   def start
  32.     start_for_timer
  33.     need_timer_scene? ? make_timer : stop_timer
  34.     puts "need_timer_scene?=#{need_timer_scene?}"
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # ● 生成计时器
  38.   #--------------------------------------------------------------------------
  39.   def make_timer
  40.     if $game_timer && make_timer_scene?
  41.       @viewport99 = Viewport.new
  42.       @viewport99.z = 201
  43.       @timer_sprite = Sprite_Timer.new(@viewport99)
  44.     end
  45.   end
  46.   #--------------------------------------------------------------------------
  47.   # ● 停止计时器
  48.   #--------------------------------------------------------------------------
  49.   def stop_timer
  50.     $game_timer.stop if $game_timer
  51.   end
  52.   #--------------------------------------------------------------------------
  53.   # ● 消除计时器
  54.   #--------------------------------------------------------------------------
  55.   alias terminate_for_timer terminate
  56.   def terminate
  57.     terminate_for_timer
  58.     @timer_sprite.dispose if @timer_sprite
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # ● 更新计时器
  62.   #--------------------------------------------------------------------------
  63.   alias update_for_timer update
  64.   def update
  65.     update_for_timer
  66.     if @timer_sprite && make_timer_scene?
  67.       $game_timer.update
  68.       @timer_sprite.update
  69.     end
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # ● 是否需要计时器
  73.   #--------------------------------------------------------------------------
  74.   def need_timer_scene?
  75.     !CLD99::Timer::SCENE_NO_TIMER.include?(SceneManager.scene.class)
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ● 是否需要额外添加计时器
  79.   #--------------------------------------------------------------------------
  80.   def make_timer_scene?
  81.     ![Scene_Map,Scene_Battle].include?(SceneManager.scene.class)
  82.   end
  83. end
  84.  
  85.  
  86. #==============================================================================
  87. # ■ Game_Timer
  88. #------------------------------------------------------------------------------
  89. #  计时器。本类的实例请参考 $game_timer 。
  90. #==============================================================================
  91. class Game_Timer
  92.   include CLD99::Timer
  93.   #--------------------------------------------------------------------------
  94.   # ● 计时器为 0 时的处理
  95.   #--------------------------------------------------------------------------
  96.   alias on_expire_for_timer on_expire
  97.   def on_expire
  98.     on_expire_for_timer
  99.     on_expire_gameover
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # ● 计时器为 0 时是否结束游戏
  103.   #--------------------------------------------------------------------------
  104.   def on_expire_gameover
  105.     case GAME_OVER_SWITCH
  106.     when -1
  107.       return
  108.     when 0  
  109.       SceneManager.goto(Scene_Gameover)
  110.     else
  111.       SceneManager.goto(Scene_Gameover) if $game_switches[GAME_OVER_SWITCH]
  112.     end
  113.   end
  114. end


关于你说的计时器重叠的问题,我等你发了脚本/工程再看看吧。
作者: alt236679    时间: 2019-1-20 12:57
KB.Driver 发表于 2019-1-19 22:59
#==============================================================================
# ■ CLD99::Timer ...

工程(没有rgss dll): game.zip (1.09 MB, 下载次数: 108)
orz
作者: KB.Driver    时间: 2019-1-20 14:43
alt236679 发表于 2019-1-20 12:57
工程(没有rgss dll):
orz

Scripts.zip (169.75 KB, 下载次数: 94)

解决了计时器数字重复显示的问题
作者: kouridea    时间: 2022-5-27 09:18
我想请教一下倒计时倒一秒就卡住是怎么回事又怎么解决?




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1