查看: 2803|回复: 13

[已经解决] 光标替换动画

[复制链接]
梦石
0
星屑
3850
在线时间
1899 小时
注册时间
2010-6-19
回帖
917
发表于 2022-9-3 15:56:11 | 显示全部楼层 |阅读模式

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

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

×
如图,下面的光标如何改成动画显示,默认光标太难看了。。。


1.png

存档界面显示人物名字等级和职业.rar (1.17 MB, 下载次数: 3)


  1. #==============================================================================
  2. # ■ Window_SaveFile
  3. #------------------------------------------------------------------------------
  4. #  显示存档以及读档画面、保存文件的窗口。
  5. #==============================================================================

  6. class Window_SaveFile < Window_Base
  7.   #--------------------------------------------------------------------------
  8.   # ● 定义实例变量
  9.   #--------------------------------------------------------------------------
  10.   attr_reader   :filename                 # 文件名
  11.   attr_reader   :selected                 # 选择状态
  12.   #--------------------------------------------------------------------------
  13.   # ● 初始化对像
  14.   #     file_index : 存档文件的索引 (0~3)
  15.   #     filename   : 文件名
  16.   #--------------------------------------------------------------------------
  17.   def initialize(file_index, filename)
  18. # 啊鲁~~这里为y坐标,宽,高做了分歧判定~~
  19.     case file_index
  20.     when 0
  21.       iy = 206+16+3-30-2
  22.       iw = 96
  23.       ih = 144
  24.       file_index =51
  25.     when 1
  26.       iy = 206+15+3-70-3
  27.       iw = 96
  28.       ih = 144
  29.       file_index = 140-7
  30.     when 2
  31.       iy = 206-12+3-16-3
  32.       iw = 96
  33.       ih = 144
  34.       file_index = 218+3
  35.     when 3
  36.       iy = 206-10+3-19-3
  37.       iw = 96
  38.       ih = 144
  39.       file_index = 317+4
  40.     when 4
  41.       iy = 206+22+3-75-4
  42.       iw = 96
  43.       ih = 144
  44.       file_index = 399+13
  45.     when 5
  46.       iy = 206-2+3-9-2
  47.       iw = 96
  48.       ih = 144
  49.       file_index = 490+4
  50.     else # 例外
  51.       iy = 206
  52.       iw = 96
  53.       ih = 144
  54.       file_index = 140+600
  55.     end
  56. # ========================
  57. super(file_index, iy, iw, ih) # 将变量代入参数~~
  58.   #  super(file_index % 6 * 90+50, iy, iw, ih) # 将变量代入参数~~
  59.     self.opacity = 0               # 这个是边框和背景都透明
  60.     self.contents = Bitmap.new(width - 32, height - 32)
  61.     @file_index = file_index
  62.     @filename = "Save#{@file_index + 1}.rxdata"
  63.     @time_stamp = Time.at(0)
  64.     @file_exist = FileTest.exist?(@filename)
  65.     if @file_exist
  66.       file = File.open(@filename, "r")
  67.       @time_stamp = file.mtime
  68.       @characters = Marshal.load(file)
  69.       @frame_count = Marshal.load(file)
  70.       @game_system = Marshal.load(file)
  71.       @game_switches = Marshal.load(file)
  72.       @game_variables = Marshal.load(file)
  73.       @total_sec = @frame_count / Graphics.frame_rate
  74.       file.close
  75.     end
  76.     refresh
  77.     @selected = false
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # ● 刷新
  81.   #--------------------------------------------------------------------------
  82.   def refresh
  83.     self.contents.clear
  84.     # 描绘文件编号
  85.     self.contents.font.color = normal_color
  86.     name = ""#"文件 #{@file_index + 1}"
  87.     self.contents.draw_text(4, 0, 600, 32, name)
  88. # 啊鲁~~其实这里是做一个记号~~就是下面会提到这里的...
  89.     @name_width = contents.text_size(name).width
  90. # ==========================
  91.     # 存档文件存在的情况下
  92.     if @file_exist
  93.       # 描绘角色
  94.       for i in 0...@characters.size
  95.         bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
  96.         cw = bitmap.rect.width / 4
  97.         ch = bitmap.rect.height / 4
  98.         src_rect = Rect.new(0, 0, cw, ch)
  99.         x = 300 - @characters.size * 32 + i * 64 - cw / 2
  100.         self.contents.blt(x, 68 - ch, bitmap, src_rect)
  101.       end
  102.       # 描绘游戏时间
  103.       hour = @total_sec / 60 / 60
  104.       min = @total_sec / 60 % 60
  105.       sec = @total_sec % 60
  106.       time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  107.       self.contents.font.color = normal_color
  108.       self.contents.draw_text(4, 8, 600, 32, time_string, 2)
  109.       # 描绘时间标记
  110.       self.contents.font.color = normal_color
  111.       time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
  112.       self.contents.draw_text(4, 40, 600, 32, time_string, 2)
  113.     end
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   # ● 设置选择状态
  117.   #     selected : 新的选择状态 (true=选择 false=不选择)
  118.   #--------------------------------------------------------------------------
  119.   def selected=(selected)
  120.     @selected = selected
  121.     update_cursor_rect
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # ● 刷新光标矩形
  125.   #--------------------------------------------------------------------------
  126.   def update_cursor_rect
  127.     if @selected
  128. # 啊鲁~~其实这里就是改光标位置和大小的地方,
  129. # 宽度就是上面做记号的那一句再加8个像素,然后高度是32,
  130. # 还有还有~~因为只在窗口里静态显示所以,坐标是固定的~~
  131.       self.cursor_rect.set(-15+5+3, -15+5+3, @name_width + 85-6, 32+110-10)
  132. # ============================
  133.     else
  134.       self.cursor_rect.empty
  135.     end
  136.   end
  137. end
复制代码
梦石
0
星屑
42345
在线时间
6022 小时
注册时间
2006-11-10
回帖
6975
发表于 2022-9-4 23:52:46 | 显示全部楼层
本帖最后由 灯笼菜刀王 于 2022-9-5 23:31 编辑
  1. class Spr_SaveFile < RPG::Sprite
  2.   def initialize(file_index)
  3.     @ary = [[1,1],[2,2],[3,3]] #这里写你的坐标数组
  4.     @t = 4  #这里写你的动画帧数比如4帧
  5.     super()
  6.     self.bitmap = RPG::Cache.windowskin("cursor.png")
  7.     @wh = self.bitmap.width / @t
  8.     @w = 0
  9.     self.src_rect.set(0,0,@wh,self.bitmap.height)
  10.     set_xy(file_index)
  11.     self.visible = false
  12.   end
  13.   def set_xy(index)
  14.     f = @ary[index] || [0,0]
  15.     self.x,self.y = f[0].to_i,f[1].to_i
  16.   end
  17.   def update
  18.     super
  19.     if Graphics.frame_count % 4 == 0
  20.       @w = (@w + 1) % @t
  21.     end
  22.     self.src_rect.set(@w * @wh,0,@wh,self.bitmap.height)
  23.   end
  24. end

  25. class Window_SaveFile < Window_Base
  26.   alias oldinitialize initialize
  27.   def initialize(file_index, filename)
  28.     oldinitialize(file_index, filename)
  29.     @aw = Spr_SaveFile.new(file_index)
  30.     self.cursor_rect.empty
  31.   end
  32.   def update_cursor_rect
  33.     @aw.visible = @selected
  34.   end
  35.   def dispose
  36.     super
  37.     @aw.dispose
  38.   end
  39.   def update
  40.     super
  41.     @aw.update
  42.   end
  43. end
复制代码


用法, 把你的光标动画切成宽高一致的数张图片,并排成一横排合并成一张, 命名为cursor.png 放到 Windowskin 文件夹里
        然后把上面的脚本塞到你这个脚本下面

设置: 在第3行数组里写你的坐标数值, 以数组写法 即 [123,456]  表示 X坐标123, Y坐标456
         在第4行写你的动画帧数
        
应该可以了吧

评分

参与人数 1星屑 +100 赞 +1 收起 理由
RyanBern + 100 + 1 认可答案

查看全部评分

回复

使用道具 举报

梦石
0
星屑
3850
在线时间
1899 小时
注册时间
2010-6-19
回帖
917
 楼主| 发表于 2022-9-5 09:13:58 | 显示全部楼层
本帖最后由 黑米馒头 于 2022-9-5 09:24 编辑
灯笼菜刀王 发表于 2022-9-4 23:52
class Window_SaveFile < Window_Base
  alias old_initialize initialize
  def initialize(file_index, f ...


@arw = Sprite_arw.new(12,20.20,30.30,40.40) #<==这里修改设置数值
不是这么改的吗?
@arw.set_xy(self.index)这句错误
3DA45AE9-670B-4A3C-BD9C-4CFEB9392280.jpeg
回复

使用道具 举报

梦石
0
星屑
42345
在线时间
6022 小时
注册时间
2006-11-10
回帖
6975
发表于 2022-9-5 10:55:45 | 显示全部楼层
黑米馒头 发表于 2022-9-5 09:13
@arw = Sprite_arw.new(12,20.20,30.30,40.40) #

呃, 父类不是window_selectable 啊.....

20行改成 @arw.set_xy(@file_index) 试试
回复

使用道具 举报

梦石
0
星屑
3850
在线时间
1899 小时
注册时间
2010-6-19
回帖
917
 楼主| 发表于 2022-9-5 12:23:45 | 显示全部楼层
本帖最后由 黑米馒头 于 2022-9-5 18:47 编辑
灯笼菜刀王 发表于 2022-9-5 10:55
呃, 父类不是window_selectable 啊.....

20行改成 @arw.set_xy(@file_index) 试试 ...


现在可以进存档界面了,不过动画坐标修改了没用,一直固定在左上脚

2.png
回复

使用道具 举报

梦石
0
星屑
42345
在线时间
6022 小时
注册时间
2006-11-10
回帖
6975
发表于 2022-9-5 22:09:09 | 显示全部楼层
黑米馒头 发表于 2022-9-5 12:23
现在可以进存档界面了,不过动画坐标修改了没用,一直固定在左上脚

...

上面那个脚本改了, 用新的试试, 注意设置变了

点评

完美解决  发表于 2022-9-6 12:25
你自己在12行加一句 self.z = 10086 就行了  发表于 2022-9-6 09:55
能否给动画加个Z坐标,现在被人物挡住了  发表于 2022-9-6 07:59
呃, 0.500 会被视为0.5, 是我没考虑周到=.= 算了, 用数组吧, 不搞奇怪操作了, 重新更新了下脚本,再试试  发表于 2022-9-5 23:22
我这么改@ary = [100.500,150.500,200.500,250.500,300.500,350.500],Y坐标没效果  发表于 2022-9-5 22:27
回复

使用道具 举报

梦石
0
星屑
3850
在线时间
1899 小时
注册时间
2010-6-19
回帖
917
 楼主| 发表于 2022-9-5 23:03:30 | 显示全部楼层
灯笼菜刀王 发表于 2022-9-5 22:09
上面那个脚本改了, 用新的试试, 注意设置变了

又上传不了图片了……

把脚本放到Rgu的工程里,就显示这样,啥情况…

Script '111' line 1: TypeError occured.
superclass mismatch for class Window SaveFile

点评

把你原来的脚本复原吧, 重新修改了下做法  发表于 2022-9-5 23:26
你这个Window_SaveFile还有别的地方用么=.= ...  发表于 2022-9-5 23:25
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部