赞 | 3 |
VIP | 1 |
好人卡 | 40 |
积分 | 1 |
经验 | 93188 |
最后登录 | 2020-7-27 |
在线时间 | 1379 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 76
- 在线时间
- 1379 小时
- 注册时间
- 2012-7-5
- 帖子
- 1698
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 kuerlulu 于 2013-10-3 10:11 编辑
原帖(其实这两个贴靠一起)
嗯 用Ruby自己的Time.now重做了这个效果,而且一点创新都没加,
唯一能说的就是代码更简单了吧】其实还可以优化的比如我可以把详细显示时刻的一行换成strftime("%X")不是更短么】何弃疗
嗯 我想说界面确实和原帖一摸一样不信看图 233那个秒是截图的问题= =
工程就不贴了,我在原来一个大坑上改的
#============================================================================== # ■ 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 when 0 week = "天" when 1 week = "一" when 2 week = "二" when 3 week = "三" when 4 week = "四" when 5 week = "五" when 6 week = "六" end case time.mon when 1..3 season = "春" when 4..6 season = "夏" when 7..9 season = "秋" when 10..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
#------------------------------------------------------------------------------
# 使用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
when 0
week = "天"
when 1
week = "一"
when 2
week = "二"
when 3
week = "三"
when 4
week = "四"
when 5
week = "五"
when 6
week = "六"
end
case time.mon
when 1..3
season = "春"
when 4..6
season = "夏"
when 7..9
season = "秋"
when 10..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天了。
激励我用功学习
#============================================================================== # ■ 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
#==============================================================================
# ■ 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做倒计时,绝逼没问题了
#============================================================================== # ■ 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
#==============================================================================
# ■ 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
|
|