设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1878|回复: 13
打印 上一主题 下一主题

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3181
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
跳转到指定楼层
1
发表于 2022-9-3 15:56:11 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

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




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


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

Lv5.捕梦者

梦石
0
星屑
37789
在线时间
5399 小时
注册时间
2006-11-10
帖子
6546
2
发表于 2022-9-4 23:52:46 | 只看该作者
本帖最后由 灯笼菜刀王 于 2022-9-5 23:31 编辑

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


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

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

评分

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

查看全部评分

回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3181
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
3
 楼主| 发表于 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)这句错误

回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
37789
在线时间
5399 小时
注册时间
2006-11-10
帖子
6546
4
发表于 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) 试试
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3181
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
5
 楼主| 发表于 2022-9-5 12:23:45 | 只看该作者
本帖最后由 黑米馒头 于 2022-9-5 18:47 编辑
灯笼菜刀王 发表于 2022-9-5 10:55
呃, 父类不是window_selectable 啊.....

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


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

回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
37789
在线时间
5399 小时
注册时间
2006-11-10
帖子
6546
6
发表于 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
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3181
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
7
 楼主| 发表于 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
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-25 13:48

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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