查看: 2259|回复: 3

[已经解决] 如何在菜单状态窗口中用图片选择人物

[复制链接]
梦石
0
星屑
635
在线时间
5 小时
注册时间
2014-5-7
回帖
2
发表于 2015-9-25 23:40:40 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 baidubb2733 于 2015-9-25 23:45 编辑

我想要的效果是,在菜单状态窗口中,用图片代表在队的角色,当选中某个角色时他的图片会变为另外一张,(相当于按钮的效果)。

我自己改的menustatus是这样的,现在能将这些图片摆在窗口中,但是因为用for添加的图片,不知道怎么修改单张图片的透明度,请问怎样写选中就能换图片的脚本呢?

刚开始学脚本,非常小白,好焦急,头像代表我的心情,跪求各位大神教教我。

[pre lang="ruby" line="1"]#==============================================================================
# ■ Window_MenuStatus
#------------------------------------------------------------------------------
#  显示菜单画面和同伴状态的窗口。
#==============================================================================

class Window_MenuStatus < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 初始化目标
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 480, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
    self.active = false
    self.index = -1
    self.z = 201
  end
   
   
   
   
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
      x = 80 + (i * 110)
      y = 420
      actor = $game_party.actors
      bitmap = Bitmap.new("Graphics/Menu/" + actor.id.to_s + "_2D")
      cw = bitmap.width
      ch = bitmap.height
      src_rect = Rect.new(0, 0, cw, ch)
      self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
    end  
    for i in 0...$game_party.actors.size
      x = 80 + (i * 110)
      y = 420
      actor = $game_party.actors
      bitmap = Bitmap.new("Graphics/Menu/" + actor.id.to_s + "_2D_2")
      cw = bitmap.width
      ch = bitmap.height
      src_rect = Rect.new(0, 0, cw, ch)
      self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)   
    end
end
  #--------------------------------------------------------------------------
  # ● 刷新光标矩形
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(0, @index * 116, self.width - 32, 96)
    end
  end
[/pre]

评分

参与人数 1星屑 +35 收起 理由
RyanBern + 35 手动认可奖励

查看全部评分

梦石
0
星屑
9716
在线时间
2775 小时
注册时间
2008-9-5
回帖
3458

开拓者短篇八RM组冠军短篇九导演组亚军白银编剧

发表于 2015-9-25 23:57:49 | 显示全部楼层
本帖最后由 cinderelmini 于 2015-9-26 00:20 编辑

唔……XP的机制怪怪的,好像只能搬运一下update的内容然后加refresh进去了。
  1. #==============================================================================
  2. # ■ Window_MenuStatus
  3. #------------------------------------------------------------------------------
  4. #  显示菜单画面和同伴状态的窗口。
  5. #==============================================================================

  6. class Window_MenuStatus < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化目标
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11.     super(0, 0, 480, 480)
  12.     self.contents = Bitmap.new(width - 32, height - 32)
  13.     refresh
  14.     self.active = false
  15.     self.index = -1
  16.     self.z = 201
  17.   end
  18.   #--------------------------------------------------------------------------
  19.   # ● 刷新
  20.   #--------------------------------------------------------------------------
  21.   def refresh
  22.     self.contents.clear
  23.     @item_max = $game_party.actors.size
  24.     for i in 0...$game_party.actors.size
  25.       x = 80 + (i * 110)
  26.       y = 420
  27.       actor = $game_party.actors[i]
  28.       file_name = i == self.index ?  "_2D" :  "_2D_2"
  29.       bitmap = Bitmap.new("Graphics/Menu/" + actor.id.to_s + file_name)
  30.       cw = bitmap.width
  31.       ch = bitmap.height
  32.       src_rect = Rect.new(0, 0, cw, ch)
  33.       self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  34.     end
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # ● 刷新光标矩形
  38.   #--------------------------------------------------------------------------
  39.    def update_cursor_rect
  40.      if @index < 0
  41.        self.cursor_rect.empty
  42.      else
  43.        self.cursor_rect.set(0, @index * 116, self.width - 32, 96)
  44.      end
  45.    end
  46.   #--------------------------------------------------------------------------
  47.   # ● 刷新画面
  48.   #--------------------------------------------------------------------------
  49.   def update
  50.     # super 不用继承
  51.     # 可以移动光标的情况下
  52.     if self.active and @item_max > 0 and @index >= 0
  53.       # 方向键下被按下的情况下
  54.       if Input.repeat?(Input::DOWN)
  55.         # 列数不是 1 并且不与方向键下的按下状态重复的情况、
  56.         # 或光标位置在(项目数-列数)之前的情况下
  57.         if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
  58.            @index < @item_max - @column_max
  59.           # 光标向下移动
  60.           $game_system.se_play($data_system.cursor_se)
  61.           @index = (@index + @column_max) % @item_max
  62.           refresh
  63.         end
  64.       end
  65.       # 方向键上被按下的情况下
  66.       if Input.repeat?(Input::UP)
  67.         # 列数不是 1 并且不与方向键下的按下状态重复的情况、
  68.         # 或光标位置在列之后的情况下
  69.         if (@column_max == 1 and Input.trigger?(Input::UP)) or
  70.            @index >= @column_max
  71.           # 光标向上移动
  72.           $game_system.se_play($data_system.cursor_se)
  73.           @index = (@index - @column_max + @item_max) % @item_max
  74.           # 刷新
  75.           refresh
  76.         end
  77.       end
  78.       # 方向键右被按下的情况下
  79.       if Input.repeat?(Input::RIGHT)
  80.         # 列数为 2 以上并且、光标位置在(项目数 - 1)之前的情况下
  81.         if @column_max >= 2 and @index < @item_max - 1
  82.           # 光标向右移动
  83.           $game_system.se_play($data_system.cursor_se)
  84.           @index += 1
  85.           # 刷新
  86.           refresh
  87.         end
  88.       end
  89.       # 方向键左被按下的情况下
  90.       if Input.repeat?(Input::LEFT)
  91.         # 列数为 2 以上并且、光标位置在 0 之后的情况下
  92.         if @column_max >= 2 and @index > 0
  93.           # 光标向左移动
  94.           $game_system.se_play($data_system.cursor_se)
  95.           @index -= 1
  96.           # 刷新
  97.           refresh
  98.         end
  99.       end
  100.       # R 键被按下的情况下
  101.       if Input.repeat?(Input::R)
  102.         # 显示的最后行在数据中最后行上方的情况下
  103.         if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
  104.           # 光标向后移动一页
  105.           $game_system.se_play($data_system.cursor_se)
  106.           @index = [@index + self.page_item_max, @item_max - 1].min
  107.           self.top_row += self.page_row_max
  108.           # 刷新
  109.           refresh
  110.         end
  111.       end
  112.       # L 键被按下的情况下
  113.       if Input.repeat?(Input::L)
  114.         # 显示的开头行在位置 0 之后的情况下
  115.         if self.top_row > 0
  116.           # 光标向前移动一页
  117.           $game_system.se_play($data_system.cursor_se)
  118.           @index = [@index - self.page_item_max, 0].max
  119.           self.top_row -= self.page_row_max
  120.           # 刷新
  121.           refresh
  122.         end
  123.       end
  124.     end
  125.     # 刷新帮助文本 (update_help 定义了继承目标)
  126.     if self.active and @help_window != nil
  127.       update_help
  128.     end
  129.     # 刷新光标矩形
  130.     update_cursor_rect
  131.   end
  132.   
  133.   #--------------------------------------------------------------------------
  134.   # ● 设置光标的位置
  135.   #     index : 新的光标位置
  136.   #--------------------------------------------------------------------------
  137.   def index=(index)
  138.     super(index)
  139.     # 刷新
  140.     refresh
  141.   end
  142. end
复制代码

评分

参与人数 1梦石 +1 收起 理由
RyanBern + 1 认可答案

查看全部评分

回复

使用道具 举报

梦石
0
星屑
635
在线时间
5 小时
注册时间
2014-5-7
回帖
2
 楼主| 发表于 2015-9-26 13:09:09 | 显示全部楼层
cinderelmini 发表于 2015-9-25 23:57
唔……XP的机制怪怪的,好像只能搬运一下update的内容然后加refresh进去了。

没想到这么快就有回复了,啊啊啊感动哭了,和我想要的效果一模一样,看了简直醍醐灌顶,十分感谢!!!
回复

使用道具 举报

梦石
0
星屑
635
在线时间
5 小时
注册时间
2014-5-7
回帖
2
 楼主| 发表于 2015-9-26 13:20:46 | 显示全部楼层
cinderelmini 发表于 2015-9-25 23:57
唔……XP的机制怪怪的,好像只能搬运一下update的内容然后加refresh进去了。

还有一个小小问题,我不太分得清refresh和update,请问怎么分辨他们呢?

点评

所以如果不是必要(比如时间窗口)的话,要在update加上各种条件,以本帖为例的话,就是按下各个方向键的时候才refresh一次,不然游戏进入菜单会很卡  发表于 2015-9-26 14:46
refresh一般是描绘窗口内容用的,因为描绘需要消耗机器资源,而且没必要持续描绘一样的东西。  发表于 2015-9-26 14:44
唔,一般来说,update是作为持续更新用的,像是窗口里的选项光框之类的,必须每帧都更新的东西。  发表于 2015-9-26 14:43
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部