查看: 2390|回复: 2

劍之飛龍的脚本小技巧

  [复制链接]

龙骑

梦石
0
星屑
615
在线时间
10 小时
注册时间
2007-12-31
回帖
1932
发表于 2008-7-1 05:48:15 | 显示全部楼层 |阅读模式

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

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

×
学脚本,就要从改脚本开始!不说那些废话开场白了,直接切入。




显示真实时间
难度:★★☆☆☆
效果图:


简单来讲,就是把菜单中的游戏时间,改成系统时间。
需要改的脚本只有Window_PlayTime 。

首先我们先了解下显示系统时间的原理。

在事件中的脚本中,输入:
  1. t = Time.now
复制代码

这就是说,为变量t代入系统的时间。
那么:
  1. t = Time.now
  2. p t.year
复制代码

就是显示现在的年份。
也就是说:
  1. 年份:year
  2. 小时:hour
  3. 分钟:min
  4. 秒数:sec
复制代码


那么,现在就打开Scene_Menu看看……显示游戏时间的是这一段:
  1.     # 生成游戏时间窗口
  2.     @playtime_window = Window_PlayTime.new
  3.     @playtime_window.x = 0
  4.     @playtime_window.y = 224
复制代码


由此可知,游戏时间是由Window_PlayTime来掌控的,一眼就可以看到:
  1.   
  2.   def refresh
  3.     self.contents.clear
  4.     self.contents.font.color = system_color
  5.     self.contents.draw_text(4, 0, 120, 32, "游戏时间")
  6.     @total_sec = Graphics.frame_count / Graphics.frame_rate
  7.     hour = @total_sec / 60 / 60
  8.     min = @total_sec / 60 % 60
  9.     sec = @total_sec % 60
  10.     text = sprintf("%02d:%02d:%02d", hour, min, sec)
  11.     self.contents.font.color = normal_color
  12.     self.contents.draw_text(4, 32, 120, 32, text, 2)
  13.   end
复制代码

所以,只要联系刚刚讲到的东西,写成:
  1.   def refresh
  2.     self.contents.clear
  3.     self.contents.font.color = system_color
  4.     self.contents.draw_text(4, 0, 120, 32, "游戏时间")
  5.     @total_sec = Graphics.frame_count / Graphics.frame_rate
  6.     hour = @total_sec / 60 / 60
  7.     min = @total_sec / 60 % 60
  8.     sec = @total_sec % 60
  9.     t = Time.now
  10.     text = sprintf("%02d时%02d分%02d秒", t.hour, t.min, t.sec)
  11.     self.contents.font.color = normal_color
  12.     self.contents.draw_text(4, 32, 120, 32, text, 2)
  13.   end
复制代码

(注意:我把“:”改成了“时”、“分”、“秒”)
再测试下,效果如上图所示。





本帖应该会继续更新,交流小技巧、经验,高手莫PIA……新手入门好用……

忘记

梦石
0
星屑
55
在线时间
4 小时
注册时间
2007-12-15
回帖
2994
发表于 2008-7-1 05:54:28 | 显示全部楼层
支持个。、虽然很基础的。。····
因为你哭泣的时候有我想你你被人嘲笑时有我陪你在你感觉最无助的那一刻有个声音鼓励
<font color=#8600E9>忘记</font>
回复

使用道具 举报

名侦探小柯

梦石
10
星屑
4393
在线时间
3739 小时
注册时间
2006-9-6
回帖
36595

极短27获奖MZ评测员开拓者贵宾第3届短篇游戏大赛主流游戏组亚军第5届短篇游戏比赛亚军

发表于 2008-7-1 05:59:02 | 显示全部楼层
能不能教一些主站上没有的东西…… [LINE]1,#dddddd[/LINE]版主对此帖的评论:『对啊』,积分『-0』。这些被扣积分的一半会用于对本帖正确答案的悬赏。
不定期回归 ~ 游戏开发之旅
———————————————————————————————
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部