查看: 82|回复: 0

[转载发布] [RMXP]时间流逝窗口?(Time实例)【2013-10-3 10:10:00更新】

[复制链接]
  • TA的每日心情
    开心
    7 天前
  • 签到天数: 37 天

    连续签到: 3 天

    [LV.5]常住居民I

    2028

    主题

    32

    回帖

    7260

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    0
    卡币
    5184
    OK点
    16
    积分
    7260
    发表于 同元一千年八月四日(秋) | 显示全部楼层 |阅读模式
    原帖(其实这两个贴靠一起)
    嗯 用Ruby自己的Time.now重做了这个效果,而且一点创新都没加,
    唯一能说的就是代码更简单了吧】其实还可以优化的比如我可以把详细显示时刻的一行换成strftime("%X")不是更短么】何弃疗
    嗯 我想说界面确实和原帖一摸一样不信看图  233那个秒是截图的问题= =
    工程就不贴了,我在原来一个大坑上改的
    RUBY 代码下载
    1. #==============================================================================
    2. # ■ Window_Time
    3. #------------------------------------------------------------------------------
    4. #  使用Time.now显示游戏时间的窗口。
    5. #==============================================================================
    6. class Window_Time < Window_Base
    7.   #--------------------------------------------------------------------------
    8.   # ● 初始化对像
    9.   #--------------------------------------------------------------------------
    10.   def initialize
    11.     super(0, 0, 640, 64)
    12.     self.contents = Bitmap.new(width - 32, height - 32)
    13.     refresh
    14.   end
    15.   #--------------------------------------------------------------------------
    16.   # ● 刷新
    17.   #--------------------------------------------------------------------------
    18.   def refresh
    19.     self.contents.clear
    20.     self.contents.font.color = system_color
    21.     #self.contents.draw_text(4, 0, 120, 32, "游戏时间")
    22.     @total_sec = Graphics.frame_count / Graphics.frame_rate
    23.     #hour = @total_sec / 60 / 60
    24.     #min = @total_sec / 60 % 60
    25.     #sec = @total_sec % 60
    26.     #text = sprintf("%02d:%02d:%02d", hour, min, sec)
    27.     # ■ %02d是指补全2位数字比如"3"自动补全成"03"
    28.     #self.contents.font.color = normal_color
    29.     #--------------------------------------------------------------------------
    30.     # ● Time类是从这里开始的
    31.     #--------------------------------------------------------------------------
    32.     time = Time.now
    33.     case time.wday
    34.       when0
    35.         week = "天"
    36.       when1
    37.         week = "一"
    38.       when2
    39.         week = "二"
    40.       when3
    41.         week = "三"
    42.       when4
    43.         week = "四"
    44.       when5
    45.         week = "五"
    46.       when6
    47.         week = "六"
    48.     end
    49.     case time.mon
    50.       when1..3
    51.         season = "春"
    52.       when4..6
    53.         season = "夏"
    54.       when7..9
    55.         season = "秋"
    56.       when10..12
    57.         season = "冬"
    58.     end
    59.     detail = sprintf("%02d:%02d:%02d", time.hour, time.min, time.sec)
    60.     text = "星期" + week + "   " + detail + "   " + season + "     "
    61.     text2 = "  " + time.year.to_s + "年" + time.month.to_s + "月" + time.day.to_s + "日"
    62.     # 这里分两个主要是为了一个左对齐一个右对齐 其实没必要
    63.     self.contents.draw_text(4, 0, 594, 32, text2)
    64.     self.contents.draw_text(4, 0, 594, 32, text, 2)
    65.   end
    66.   #--------------------------------------------------------------------------
    67.   # ● 刷新画面
    68.   #--------------------------------------------------------------------------
    69.   def update
    70.     super
    71.     if Graphics.frame_count / Graphics.frame_rate != @total_sec
    72.       refresh
    73.     end
    74.   end
    75. end
    复制代码

    我无聊吧,连原帖做的Window_Time的类名都没改,所以如果你要把这两个脚本放一块绝逼会被重定义。。
    嗯,要显示在Scene_Map的话就加一句显示Time窗口的代码就行了,不要忘了在下面加上.update(第一次弄的时候看到时间不动好捉急)
    实际上Time.now能做很多事,比如计算时间差这种神奇的方法。
    就到这里了
    我真的不是在那啥原作者数字君@876加几  


    我TM真无聊
    正如你所见这是个倒计时,而且是采用了小学算术原理 ,其实用总秒数也是可以做的。
    当然这个倒计时会有不符合常理的地方,比如月的计算到底是当30天还是31天,总之我是默认30天了。
    激励我用功学习
    RUBY 代码下载
    1. #==============================================================================
    2. # ■ Window_Time2
    3. #------------------------------------------------------------------------------
    4. #  我要一个显示剩余时间的窗口。
    5. #==============================================================================
    6. class Window_Time2 < Window_Base
    7.   #--------------------------------------------------------------------------
    8.   # ● 初始化对像
    9.   #--------------------------------------------------------------------------
    10.   def initialize
    11.     super(0, 0, 640, 64)
    12.     self.contents = Bitmap.new(width - 32, height - 32)
    13.     self.opacity = 160
    14.     # ■剩余时间变量初始化■
    15.     @leftyear = 0
    16.     @leftmon = 0
    17.     @leftday = 0
    18.     @lefthour = 0
    19.     @leftmin = 0
    20.     @leftsec = 0
    21.     @left = "还有"
    22.     refresh
    23.   end
    24.   #--------------------------------------------------------------------------
    25.   # ● 刷新
    26.   #--------------------------------------------------------------------------
    27.   def refresh
    28.     # ■来设定目标时间吧■年月日时分秒[如果光用算法来做的话]
    29.     target = "高考"
    30.     targetyear = 2015
    31.     targetmon = 6
    32.     targetday = 7
    33.     targethour = 7
    34.     targetmin = 0
    35.     targetsec = 0
    36.     self.contents.clear
    37.     self.contents.font.color = system_color
    38.     @total_sec = Graphics.frame_count / Graphics.frame_rate
    39.     #text = sprintf("%02d:%02d:%02d", hour, min, sec)
    40.     # ■ %02d是指补全2位数字比如"3"自动补全成"03"
    41.     #--------------------------------------------------------------------------
    42.     # ● Time类是从这里开始的
    43.     #--------------------------------------------------------------------------
    44.     time = Time.now
    45.     #--------------------------------------------------------------------------
    46.     # ● 算法部分(2) 小学算术(减法)原理= =|||:先算末尾再推进
    47.     #--------------------------------------------------------------------------
    48.     if targetsec - time.sec < 0
    49.       @leftmin -= 1
    50.       @leftsec = 60 + targetsec - time.sec
    51.     else
    52.       @leftsec = targetsec - time.sec
    53.     end
    54.     if targetmin - time.min < 0
    55.       @lefthour -= 1
    56.       @leftmin = 60 + targetmin - time.min
    57.     else
    58.       @leftmin = targetmin - time.min
    59.     end
    60.     if targethour - time.hour < 0
    61.       @leftday -= 1
    62.       @lefthour = 24 + targethour - time.hour
    63.     else
    64.       @lefthour = targethour - time.hour
    65.     end
    66.     if targetday - time.day < 0
    67.       @leftmon -= 1
    68.       @leftday = 30 + targetday - time.day# ■这样写绝逼会产生1-2天的误差 我猜
    69.     else
    70.       @leftday = targetday - time.day
    71.     end
    72.     if targetmon - time.mon < 0
    73.       @leftyear -= 1
    74.       @leftmon = 12 + targetmon - time.mon
    75.     else
    76.       @leftmon = targetmon - time.mon
    77.     end
    78.     if targetyear - time.year < 0
    79.       @left = "已过"
    80.       @leftyear = -(targetyear - time.year)
    81.     else
    82.       @leftyear = targetyear - time.year
    83.     end
    84.     #--------------------------------------------------------------------------
    85.     text = "距离 "+ target + " " + @left + @leftyear.to_s + "年" + @leftmon.to_s + "月" + @leftday.to_s + "天" + @lefthour.to_s + "小时" + @leftmin.to_s + "分钟" + @leftsec.to_s + "秒"
    86.     self.contents.draw_text(4, 0, 594, 32, text, 2)
    87.   end
    88.   #--------------------------------------------------------------------------
    89.   # ● 刷新画面
    90.   #--------------------------------------------------------------------------
    91.   def update
    92.     super
    93.     if Graphics.frame_count / Graphics.frame_rate != @total_sec
    94.       refresh
    95.     end
    96.   end
    97. end
    复制代码

    这是对Time的怨念

    最终更新,用mktime做倒计时,绝逼没问题了

    RUBY 代码
    1. #==============================================================================
    2. # ■ Window_Time2
    3. #------------------------------------------------------------------------------
    4. #  我要一个显示剩余时间的窗口。
    5. #==============================================================================
    6. class Window_Time2 < Window_Base
    7.   #--------------------------------------------------------------------------
    8.   # ● 初始化对像
    9.   #--------------------------------------------------------------------------
    10.   def initialize
    11.     super(0, 64, 640, 64)
    12.     self.contents = Bitmap.new(width - 32, height - 32)
    13.     self.opacity = 160
    14. #    # ■剩余时间变量初始化■
    15. #    @leftyear = 0
    16. #    @leftmon = 0
    17.     @leftday = 0
    18.     @lefthour = 0
    19.     @leftmin = 0
    20.     @leftsec = 0
    21.     @left = "还有"
    22.     refresh
    23.   end
    24.   #--------------------------------------------------------------------------
    25.   # ● 刷新
    26.   #--------------------------------------------------------------------------
    27.   def refresh
    28.     # ■来设定目标时间吧■年月日时分秒[如果光用算法来做的话]
    29.     target = "高考"
    30.     targetyear = 2015
    31.     targetmon = 6
    32.     targetday = 7
    33.     targethour = 7
    34.     targetmin = 0
    35.     targetsec = 0
    36.     self.contents.clear
    37.     self.contents.font.color = system_color
    38.     @total_sec = Graphics.frame_count / Graphics.frame_rate
    39.     #text = sprintf("%02d:%02d:%02d", hour, min, sec)
    40.     # ■ %02d是指补全2位数字比如"3"自动补全成"03"
    41.     #--------------------------------------------------------------------------
    42.     # ● Time类是从这里开始的
    43.     #--------------------------------------------------------------------------
    44.     time = Time.now
    45.     targettime = Time.mktime(targetyear, targetmon, targetday, targethour, targetmin, targetsec)
    46.     totalsec = targettime - time
    47.     if totalsec >= 0
    48.       @left = "还有"
    49.     else
    50.       @left = "已过"
    51.       totalsec = time - targettime
    52.     end
    53.     @leftday = totalsec.to_i / 86400
    54.     @lefthour = (totalsec.to_i % 86400) / 60 / 60
    55.     @leftmin = totalsec.to_i / 60 % 60
    56.     @leftsec = totalsec.to_i % 60
    57.     #--------------------------------------------------------------------------
    58.     #text2 = "       距离 "+ target + " " + @left + @leftyear.to_s + "年" + @leftmon.to_s + "月" + @leftday.to_s + "天" + @lefthour.to_s + "小时" + @leftmin.to_s + "分钟" + @leftsec.to_s + "秒"
    59.     text = "          距离" + " " + target + " " + @left + @leftday.to_s + "天" + @lefthour.to_s + "时" + @leftmin.to_s + "分" + @leftsec.to_s + "秒"
    60.     self.contents.draw_text(4, 0, 594, 32, text)
    61.   end
    62.   #--------------------------------------------------------------------------
    63.   # ● 刷新画面
    64.   #--------------------------------------------------------------------------
    65.   def update
    66.     super
    67.     if Graphics.frame_count / Graphics.frame_rate != @total_sec
    68.       refresh
    69.     end
    70.   end
    71. end
    复制代码

                 本帖来自P1论坛作者kuerlulu,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=332877  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。

    本帖子中包含更多资源

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

    x
    天天去同能,天天有童年!
    回复 论坛版权

    使用道具 举报

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

    本版积分规则

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2024-5-17 18:53 , Processed in 0.062731 second(s), 44 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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