[RMXP]时间流逝窗口?(Time实例)【2013-10-3 10:10:00更新】
原帖(其实这两个贴靠一起)嗯 用Ruby自己的Time.now重做了这个效果,而且一点创新都没加,
唯一能说的就是代码更简单了吧】其实还可以优化的比如我可以把详细显示时刻的一行换成strftime("%X")不是更短么】何弃疗
嗯 我想说界面确实和原帖一摸一样不信看图233那个秒是截图的问题= =
工程就不贴了,我在原来一个大坑上改的
RUBY 代码下载
#==============================================================================
# ■ Window_Time
#------------------------------------------------------------------------------
# 使用Time.now显示游戏时间的窗口。
#==============================================================================
class Window_Time < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
#self.contents.draw_text(4, 0, 120, 32, "游戏时间")
@total_sec = Graphics.frame_count / Graphics.frame_rate
#hour = @total_sec / 60 / 60
#min = @total_sec / 60 % 60
#sec = @total_sec % 60
#text = sprintf("%02d:%02d:%02d", hour, min, sec)
# ■ %02d是指补全2位数字比如"3"自动补全成"03"
#self.contents.font.color = normal_color
#--------------------------------------------------------------------------
# ● Time类是从这里开始的
#--------------------------------------------------------------------------
time = Time.now
case time.wday
when0
week = "天"
when1
week = "一"
when2
week = "二"
when3
week = "三"
when4
week = "四"
when5
week = "五"
when6
week = "六"
end
case time.mon
when1..3
season = "春"
when4..6
season = "夏"
when7..9
season = "秋"
when10..12
season = "冬"
end
detail = sprintf("%02d:%02d:%02d", time.hour, time.min, time.sec)
text = "星期" + week + " " + detail + " " + season + " "
text2 = "" + time.year.to_s + "年" + time.month.to_s + "月" + time.day.to_s + "日"
# 这里分两个主要是为了一个左对齐一个右对齐 其实没必要
self.contents.draw_text(4, 0, 594, 32, text2)
self.contents.draw_text(4, 0, 594, 32, text, 2)
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
super
if Graphics.frame_count / Graphics.frame_rate != @total_sec
refresh
end
end
end
我无聊吧,连原帖做的Window_Time的类名都没改,所以如果你要把这两个脚本放一块绝逼会被重定义。。
嗯,要显示在Scene_Map的话就加一句显示Time窗口的代码就行了,不要忘了在下面加上.update(第一次弄的时候看到时间不动好捉急)
实际上Time.now能做很多事,比如计算时间差这种神奇的方法。
就到这里了
我真的不是在那啥原作者数字君@876加几
我TM真无聊
正如你所见这是个倒计时,而且是采用了小学算术原理 ,其实用总秒数也是可以做的。
当然这个倒计时会有不符合常理的地方,比如月的计算到底是当30天还是31天,总之我是默认30天了。
激励我用功学习
RUBY 代码下载
#==============================================================================
# ■ Window_Time2
#------------------------------------------------------------------------------
# 我要一个显示剩余时间的窗口。
#==============================================================================
class Window_Time2 < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 160
# ■剩余时间变量初始化■
@leftyear = 0
@leftmon = 0
@leftday = 0
@lefthour = 0
@leftmin = 0
@leftsec = 0
@left = "还有"
refresh
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
# ■来设定目标时间吧■年月日时分秒[如果光用算法来做的话]
target = "高考"
targetyear = 2015
targetmon = 6
targetday = 7
targethour = 7
targetmin = 0
targetsec = 0
self.contents.clear
self.contents.font.color = system_color
@total_sec = Graphics.frame_count / Graphics.frame_rate
#text = sprintf("%02d:%02d:%02d", hour, min, sec)
# ■ %02d是指补全2位数字比如"3"自动补全成"03"
#--------------------------------------------------------------------------
# ● Time类是从这里开始的
#--------------------------------------------------------------------------
time = Time.now
#--------------------------------------------------------------------------
# ● 算法部分(2) 小学算术(减法)原理= =|||:先算末尾再推进
#--------------------------------------------------------------------------
if targetsec - time.sec < 0
@leftmin -= 1
@leftsec = 60 + targetsec - time.sec
else
@leftsec = targetsec - time.sec
end
if targetmin - time.min < 0
@lefthour -= 1
@leftmin = 60 + targetmin - time.min
else
@leftmin = targetmin - time.min
end
if targethour - time.hour < 0
@leftday -= 1
@lefthour = 24 + targethour - time.hour
else
@lefthour = targethour - time.hour
end
if targetday - time.day < 0
@leftmon -= 1
@leftday = 30 + targetday - time.day# ■这样写绝逼会产生1-2天的误差 我猜
else
@leftday = targetday - time.day
end
if targetmon - time.mon < 0
@leftyear -= 1
@leftmon = 12 + targetmon - time.mon
else
@leftmon = targetmon - time.mon
end
if targetyear - time.year < 0
@left = "已过"
@leftyear = -(targetyear - time.year)
else
@leftyear = targetyear - time.year
end
#--------------------------------------------------------------------------
text = "距离 "+ target + " " + @left + @leftyear.to_s + "年" + @leftmon.to_s + "月" + @leftday.to_s + "天" + @lefthour.to_s + "小时" + @leftmin.to_s + "分钟" + @leftsec.to_s + "秒"
self.contents.draw_text(4, 0, 594, 32, text, 2)
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
super
if Graphics.frame_count / Graphics.frame_rate != @total_sec
refresh
end
end
end
这是对Time的怨念
最终更新,用mktime做倒计时,绝逼没问题了
RUBY 代码
#==============================================================================
# ■ Window_Time2
#------------------------------------------------------------------------------
# 我要一个显示剩余时间的窗口。
#==============================================================================
class Window_Time2 < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super(0, 64, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 160
# # ■剩余时间变量初始化■
# @leftyear = 0
# @leftmon = 0
@leftday = 0
@lefthour = 0
@leftmin = 0
@leftsec = 0
@left = "还有"
refresh
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
# ■来设定目标时间吧■年月日时分秒[如果光用算法来做的话]
target = "高考"
targetyear = 2015
targetmon = 6
targetday = 7
targethour = 7
targetmin = 0
targetsec = 0
self.contents.clear
self.contents.font.color = system_color
@total_sec = Graphics.frame_count / Graphics.frame_rate
#text = sprintf("%02d:%02d:%02d", hour, min, sec)
# ■ %02d是指补全2位数字比如"3"自动补全成"03"
#--------------------------------------------------------------------------
# ● Time类是从这里开始的
#--------------------------------------------------------------------------
time = Time.now
targettime = Time.mktime(targetyear, targetmon, targetday, targethour, targetmin, targetsec)
totalsec = targettime - time
if totalsec >= 0
@left = "还有"
else
@left = "已过"
totalsec = time - targettime
end
@leftday = totalsec.to_i / 86400
@lefthour = (totalsec.to_i % 86400) / 60 / 60
@leftmin = totalsec.to_i / 60 % 60
@leftsec = totalsec.to_i % 60
#--------------------------------------------------------------------------
#text2 = " 距离 "+ target + " " + @left + @leftyear.to_s + "年" + @leftmon.to_s + "月" + @leftday.to_s + "天" + @lefthour.to_s + "小时" + @leftmin.to_s + "分钟" + @leftsec.to_s + "秒"
text = " 距离" + " " + target + " " + @left + @leftday.to_s + "天" + @lefthour.to_s + "时" + @leftmin.to_s + "分" + @leftsec.to_s + "秒"
self.contents.draw_text(4, 0, 594, 32, text)
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
super
if Graphics.frame_count / Graphics.frame_rate != @total_sec
refresh
end
end
end
本帖来自P1论坛作者kuerlulu,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=332877若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页:
[1]