查看: 2716|回复: 13

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

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

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

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

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


1.png

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


[pre lang="ruby"]#==============================================================================
# ■ Window_SaveFile
#------------------------------------------------------------------------------
#  显示存档以及读档画面、保存文件的窗口。
#==============================================================================

class Window_SaveFile < Window_Base
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader   :filename                 # 文件名
  attr_reader   :selected                 # 选择状态
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #     file_index : 存档文件的索引 (0~3)
  #     filename   : 文件名
  #--------------------------------------------------------------------------
  def initialize(file_index, filename)
# 啊鲁~~这里为y坐标,宽,高做了分歧判定~~
    case file_index
    when 0
      iy = 206+16+3-30-2
      iw = 96
      ih = 144
      file_index =51
    when 1
      iy = 206+15+3-70-3
      iw = 96
      ih = 144
      file_index = 140-7
    when 2
      iy = 206-12+3-16-3
      iw = 96
      ih = 144
      file_index = 218+3
    when 3
      iy = 206-10+3-19-3
      iw = 96
      ih = 144
      file_index = 317+4
    when 4
      iy = 206+22+3-75-4
      iw = 96
      ih = 144
      file_index = 399+13
    when 5
      iy = 206-2+3-9-2
      iw = 96
      ih = 144
      file_index = 490+4
    else # 例外
      iy = 206
      iw = 96
      ih = 144
      file_index = 140+600
    end
# ========================
super(file_index, iy, iw, ih) # 将变量代入参数~~
  #  super(file_index % 6 * 90+50, iy, iw, ih) # 将变量代入参数~~
    self.opacity = 0               # 这个是边框和背景都透明
    self.contents = Bitmap.new(width - 32, height - 32)
    @file_index = file_index
    @filename = "Save#{@file_index + 1}.rxdata"
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      @characters = Marshal.load(file)
      @frame_count = Marshal.load(file)
      @game_system = Marshal.load(file)
      @game_switches = Marshal.load(file)
      @game_variables = Marshal.load(file)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
    refresh
    @selected = false
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    # 描绘文件编号
    self.contents.font.color = normal_color
    name = ""#"文件 #{@file_index + 1}"
    self.contents.draw_text(4, 0, 600, 32, name)
# 啊鲁~~其实这里是做一个记号~~就是下面会提到这里的...
    @name_width = contents.text_size(name).width
# ==========================
    # 存档文件存在的情况下
    if @file_exist
      # 描绘角色
      for i in 0...@characters.size
        bitmap = RPG::Cache.character(@characters[0], @characters[1])
        cw = bitmap.rect.width / 4
        ch = bitmap.rect.height / 4
        src_rect = Rect.new(0, 0, cw, ch)
        x = 300 - @characters.size * 32 + i * 64 - cw / 2
        self.contents.blt(x, 68 - ch, bitmap, src_rect)
      end
      # 描绘游戏时间
      hour = @total_sec / 60 / 60
      min = @total_sec / 60 % 60
      sec = @total_sec % 60
      time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
      self.contents.font.color = normal_color
      self.contents.draw_text(4, 8, 600, 32, time_string, 2)
      # 描绘时间标记
      self.contents.font.color = normal_color
      time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
      self.contents.draw_text(4, 40, 600, 32, time_string, 2)
    end
  end
  #--------------------------------------------------------------------------
  # ● 设置选择状态
  #     selected : 新的选择状态 (true=选择 false=不选择)
  #--------------------------------------------------------------------------
  def selected=(selected)
    @selected = selected
    update_cursor_rect
  end
  #--------------------------------------------------------------------------
  # ● 刷新光标矩形
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @selected
# 啊鲁~~其实这里就是改光标位置和大小的地方,
# 宽度就是上面做记号的那一句再加8个像素,然后高度是32,
# 还有还有~~因为只在窗口里静态显示所以,坐标是固定的~~
      self.cursor_rect.set(-15+5+3, -15+5+3, @name_width + 85-6, 32+110-10)
# ============================
    else
      self.cursor_rect.empty
    end
  end
end
[/pre]
梦石
0
星屑
42235
在线时间
6017 小时
注册时间
2006-11-10
回帖
6966
发表于 2022-9-4 23:52:46 | 显示全部楼层
本帖最后由 灯笼菜刀王 于 2022-9-5 23:31 编辑

[pre lang="ruby"]class Spr_SaveFile < RPG::Sprite
  def initialize(file_index)
    @ary = [[1,1],[2,2],[3,3]] #这里写你的坐标数组
    @t = 4  #这里写你的动画帧数比如4帧
    super()
    self.bitmap = RPG::Cache.windowskin("cursor.png")
    @wh = self.bitmap.width / @t
    @w = 0
    self.src_rect.set(0,0,@wh,self.bitmap.height)
    set_xy(file_index)
    self.visible = false
  end
  def set_xy(index)
    f = @ary[index] || [0,0]
    self.x,self.y = f[0].to_i,f[1].to_i
  end
  def update
    super
    if Graphics.frame_count % 4 == 0
      @w = (@w + 1) % @t
    end
    self.src_rect.set(@w * @wh,0,@wh,self.bitmap.height)
  end
end

class Window_SaveFile < Window_Base
  alias oldinitialize initialize
  def initialize(file_index, filename)
    oldinitialize(file_index, filename)
    @aw = Spr_SaveFile.new(file_index)
    self.cursor_rect.empty
  end
  def update_cursor_rect
    @aw.visible = @selected
  end
  def dispose
    super
    @aw.dispose
  end
  def update
    super
    @aw.update
  end
end[/pre]

用法, 把你的光标动画切成宽高一致的数张图片,并排成一横排合并成一张, 命名为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
星屑
42235
在线时间
6017 小时
注册时间
2006-11-10
回帖
6966
发表于 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
星屑
42235
在线时间
6017 小时
注册时间
2006-11-10
回帖
6966
发表于 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.

在本版发帖返回顶部