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

Project1

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

[已经解决] 窗口刷新

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
122 小时
注册时间
2009-6-12
帖子
73
跳转到指定楼层
1
发表于 2011-5-8 14:04:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
帮我看看
#==============================================================================
# ■ Window_Target
#------------------------------------------------------------------------------
#  物品画面与特技画面的、使用对像角色选择窗口。
#==============================================================================

class Window_Target < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 初始化对象
  #--------------------------------------------------------------------------
  def initialize
    super(460, 32, 200, 410)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    self.active = false
    @item_max = $game_party.actors.size
    self.cursor_rect.empty                                
    @cursor = Sprite_Cursor.new   
    $select = []
    for i in 0...@item_max
      $select[i] = false         
    end
    $refresh_variable = 0
    refresh
    refresh_face
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.size = 12
    self.contents.font.color = Color.new( 0, 0, 0, 255)
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      # 描绘角色状态
      bitmap = RPG::Cache.picture("人物状态背景.png" )
      self.contents.blt( -8 ,97 * i - 2,bitmap,Rect.new(0,0,bitmap.width,bitmap.height ))
      draw_actor_name(actor, 139, 35 + 97 * i)
      # 描绘HP,SP
      self.contents.draw_text( - 3, 97 * i, 48, 32, actor.hp.to_s, 2)
      self.contents.draw_text( 45, 97 * i, 12, 32, "/")
      self.contents.draw_text( 51, 97 * i, 48, 32, actor.maxhp.to_s)
      self.contents.draw_text( - 3, 46 + 97 * i, 48, 32, actor.sp.to_s, 2)
      self.contents.draw_text( 45, 46 + 97 * i, 12, 32, "/")
      self.contents.draw_text( 51, 46 + 97 * i, 48, 32, actor.maxsp.to_s)
      # 描绘HP,SP条
      draw_actor_hp_meter_line(actor, 18, 24 + 97 * i, 62, 4)
      draw_actor_sp_meter_line(actor, 18, 70 + 97 * i, 63, 4)
      # 描绘MP,MP条
      @actor_mp = $game_variables[26 + i]
      @actor_maxmp = $game_variables[31 + i]
      self.contents.draw_text( - 10, 23 + 97 * i, 48, 32, @actor_mp.to_s, 2)
      self.contents.draw_text( 38, 23 + 97 * i, 12, 32, "/")
      self.contents.draw_text( 44, 23 + 97 * i, 48, 32, @actor_maxmp.to_s)
      draw_actor_mp_meter_line(actor, 12, 47 + 97 * i, 62, 4)
    end
  end
  # 有改动的地方单独刷新,以提高游戏运行效率
  def refresh_face
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      # 描绘角色头像
      if $select[i] == true
        bitmap = RPG::Cache.battler(actor.name + "头像2" , actor.battler_hue)
      else
        bitmap = RPG::Cache.battler(actor.name + "头像1" , actor.battler_hue)
      end
      rect = Rect.new(0,0,bitmap.width,bitmap.height)
      self.contents.blt(95,12 + 97 * i,bitmap,rect)
    end
  end
  #-------------------------------------------------------------------------
  # ● 定义角色名称
  #-------------------------------------------------------------------------
  def draw_actor_name(actor,x,y)
    bitmap = RPG::Cache.battler(actor.name , actor.battler_hue)
    self.contents.blt(x,y,bitmap,Rect.new(0,0,bitmap.width,bitmap.height ))
  end
  #--------------------------------------------------------------------------
  # ● ライン描画 by 桜雅 在土
  #--------------------------------------------------------------------------
  def draw_line(start_x, start_y, end_x, end_y, start_color, width = 1, end_color = start_color)
    # 描写距離の計算。大きめに直角時の長さ。
    distance = (start_x - end_x).abs + (start_y - end_y).abs
    # 描写開始
    if end_color == start_color
      for i in 1..distance
        x = (start_x + (end_x - start_x) * i / distance).to_i
        y = (start_y + (end_y - start_y) * i / distance).to_i
        if width == 1
          self.contents.set_pixel(x, y, start_color)
        else
          self.contents.fill_rect(x, y, width, width, start_color)
        end
      end
    else
      for i in 1..distance
        x = (start_x + (end_x - start_x) * i / distance).to_i
        y = (start_y + (end_y - start_y) * i / distance).to_i
        r = start_color.red * (distance-i)/distance + end_color.red * i/distance
        g = start_color.green * (distance-i)/distance + end_color.green * i/distance
        b = start_color.blue * (distance-i)/distance + end_color.blue * i/distance
        a = start_color.alpha * (distance-i)/distance + end_color.alpha * i/distance
        if width == 1
          self.contents.set_pixel(x, y, Color.new(r, g, b, a))
        else
          self.contents.fill_rect(x, y, width, width, Color.new(r, g, b, a))
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● HP的描画
  #--------------------------------------------------------------------------
  def draw_actor_hp_meter_line(actor, x, y, width = 156, height = 4)
    w = width * actor.hp / actor.maxhp
    hp_color_1 = Color.new(229, 188, 245, 255)
    hp_color_2 = Color.new(171, 59, 245, 255)
    i = 0
    for i in 0..3
     draw_line(x + width - w, y, x + width , y, hp_color_1, 1, hp_color_2)
     y += 1
     i += 1
    end
  end
  #--------------------------------------------------------------------------
  # ● SP的描画
  #--------------------------------------------------------------------------
  def draw_actor_sp_meter_line(actor, x, y, width = 156, height = 4)
    w = width * actor.sp / actor.maxsp
    sp_color_1 = Color.new( 245, 209, 187, 255)
    sp_color_2 = Color.new( 250, 117, 65, 255)
    for i in 0..3
      draw_line(x + width - w, y, x + width , y, sp_color_1, 1, sp_color_2)
      y += 1
      i += 1
    end
  end
  #--------------------------------------------------------------------------
  # ● MP的描画
  #--------------------------------------------------------------------------
  def draw_actor_mp_meter_line(actor, x, y, width = 156, height = 4)
    w = width * @actor_mp / @actor_maxmp
    mp_color_1 = Color.new( 187, 225, 245, 255)
    mp_color_2 = Color.new( 65, 193, 253, 255)
    for i in 0..3
      draw_line(x + width - w, y, x + width , y, mp_color_1, 1, mp_color_2)
      y += 1
      i += 1
    end
  end
  #--------------------------------------------------------------------------
  # ● 更新光标矩形
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # 光标位置不满 0 的情况下
    if @index < 0 or self.active == false
      @cursor.visible = false
      return
    end
    @cursor.visible = true if self.visible && self.active
    @cursor.opacitysz(1) if @cursor.opacity < 255
    # 获取当前的行
    row = @index / @column_max
    # 当前行被显示开头行前面的情况下
    if row < self.top_row
      # 从当前行向开头行滚动
      self.top_row = row
    end
    # 当前行被显示末尾行之后的情况下
    if row > self.top_row + (self.page_row_max - 1)
      # 从当前行向末尾滚动
      self.top_row = row - (self.page_row_max - 1)
    end
    # 更新光标位置
    @cursor.x = self.x + 128
    @cursor.y = self.y + @index * 97 + 100
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面
  #--------------------------------------------------------------------------
def cursor_update
   @cursor.update if @cursor.visible and @cursor.opacity == 255 and
   self.active and @item_max >= 1
   if self.active and @item_max > 0 and @index >= 0
     index_var = @index
     mouse_x, mouse_y = Mouse.get_mouse_pos
     mouse_not_in_rect = true
     for i in 0...@item_max
       @index = i
       update_cursor_rect
       if (mouse_x > 565) and (mouse_y > 55 + i * 97) and
          (mouse_x < 625) and (mouse_y < 135 + i * 97)
         mouse_not_in_rect = false
         $select[i] = true
         if $refresh_variable == 0
           $game_system.se_play($data_system.cursor_se)
           refresh_face
         end
         $refresh_variable +=1
         break
       end
     end
     if mouse_not_in_rect
       $refresh_variable = 0
       @index = index_var
       update_cursor_rect
       for i in 0...@item_max
         $select[i] = false
       end
       refresh_face
       Mouse.click_lock
     else
       Mouse.click_unlock               
     end
   end
   # 刷新光标矩形
   update_cursor_rect
end
  
  def dispose              
    @cursor.dispose              
    super                  
  end
end

把refresh中要刷新的一部分放到def refresh_face中刷新,可是每次刷新后原来的内容不会清空,两张图片就重叠在一起了,如果加了self.contents.clear就会把refresh中的内容也清空掉

点评

啊不是代码  发表于 2011-5-8 18:57
能用脚本发一下么,改法基本清楚了  发表于 2011-5-8 18:56

Lv1.梦旅人

虱子

梦石
0
星屑
121
在线时间
1782 小时
注册时间
2010-6-19
帖子
3597
2
发表于 2011-5-8 18:58:28 | 只看该作者
  1.       rect = Rect.new(0,0,bitmap.width,bitmap.height)
  2.       self.contents.blt(95,12 + 97 * i,bitmap,rect)
复制代码
这个Rect的x和y坐标都是0,所有头像都是在这个Rect里描绘的,自然会重叠在一起

http://rpg.blue/thread-175056-1-2.html
PVZ型塔防物一个
http://rpg.blue/thread-155199-1-2.html
RMXP技术讨论区手动认可帖,得到答案请认可
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
122 小时
注册时间
2009-6-12
帖子
73
3
 楼主| 发表于 2011-5-9 14:00:25 | 只看该作者
回复 Wind2010 的帖子

那有什么解决方法没有?


flyfairy于2011-5-9 14:05补充以下内容:
  1. #==============================================================================
  2. # ■ Window_Target
  3. #------------------------------------------------------------------------------
  4. #  物品画面与特技画面的、使用对像角色选择窗口。
  5. #==============================================================================

  6. class Window_Target < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对象
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11.     super(460, 32, 200, 410)
  12.     self.contents = Bitmap.new(width - 32, height - 32)
  13.     self.opacity = 0
  14.     self.active = false
  15.     @item_max = $game_party.actors.size
  16.     self.cursor_rect.empty                                
  17.     @cursor = Sprite_Cursor.new   
  18.     $select = []
  19.     for i in 0...@item_max
  20.       $select[i] = false         
  21.     end
  22.     $refresh_variable = 0
  23.     refresh
  24.     refresh_face
  25.   end
  26.   #--------------------------------------------------------------------------
  27.   # ● 刷新
  28.   #--------------------------------------------------------------------------
  29.   def refresh
  30.     self.contents.clear
  31.     self.contents.font.size = 12
  32.     self.contents.font.color = Color.new( 0, 0, 0, 255)
  33.     for i in 0...$game_party.actors.size
  34.       actor = $game_party.actors[i]
  35.       # 描绘角色状态
  36.       bitmap = RPG::Cache.picture("人物状态背景.png" )
  37.       self.contents.blt( -8 ,97 * i - 2,bitmap,Rect.new(0,0,bitmap.width,bitmap.height ))
  38.       draw_actor_name(actor, 139, 35 + 97 * i)
  39.       # 描绘HP,SP
  40.       self.contents.draw_text( - 3, 97 * i, 48, 32, actor.hp.to_s, 2)
  41.       self.contents.draw_text( 45, 97 * i, 12, 32, "/")
  42.       self.contents.draw_text( 51, 97 * i, 48, 32, actor.maxhp.to_s)
  43.       self.contents.draw_text( - 3, 46 + 97 * i, 48, 32, actor.sp.to_s, 2)
  44.       self.contents.draw_text( 45, 46 + 97 * i, 12, 32, "/")
  45.       self.contents.draw_text( 51, 46 + 97 * i, 48, 32, actor.maxsp.to_s)
  46.       # 描绘HP,SP条
  47.       draw_actor_hp_meter_line(actor, 18, 24 + 97 * i, 62, 4)
  48.       draw_actor_sp_meter_line(actor, 18, 70 + 97 * i, 63, 4)
  49.       # 描绘MP,MP条
  50.       @actor_mp = $game_variables[26 + i]
  51.       @actor_maxmp = $game_variables[31 + i]
  52.       self.contents.draw_text( - 10, 23 + 97 * i, 48, 32, @actor_mp.to_s, 2)
  53.       self.contents.draw_text( 38, 23 + 97 * i, 12, 32, "/")
  54.       self.contents.draw_text( 44, 23 + 97 * i, 48, 32, @actor_maxmp.to_s)
  55.       draw_actor_mp_meter_line(actor, 12, 47 + 97 * i, 62, 4)
  56.     end
  57.   end
  58.   # 有改动的地方单独刷新,以提高游戏运行效率
  59.   def refresh_face
  60.     for i in 0...$game_party.actors.size
  61.       actor = $game_party.actors[i]
  62.       # 描绘角色头像
  63.       if $select[i] == true
  64.         bitmap = RPG::Cache.battler(actor.name + "头像2" , actor.battler_hue)
  65.       else
  66.         bitmap = RPG::Cache.battler(actor.name + "头像1" , actor.battler_hue)
  67.       end
  68.       rect = Rect.new(0,0,bitmap.width,bitmap.height)
  69.       self.contents.blt(95,12 + 97 * i,bitmap,rect)
  70.     end
  71.   end
  72.   #-------------------------------------------------------------------------
  73.   # ● 定义角色名称
  74.   #-------------------------------------------------------------------------
  75.   def draw_actor_name(actor,x,y)
  76.     bitmap = RPG::Cache.battler(actor.name , actor.battler_hue)
  77.     self.contents.blt(x,y,bitmap,Rect.new(0,0,bitmap.width,bitmap.height ))
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # ● ライン描画 by 桜雅 在土
  81.   #--------------------------------------------------------------------------
  82.   def draw_line(start_x, start_y, end_x, end_y, start_color, width = 1, end_color = start_color)
  83.     # 描写距離の計算。大きめに直角時の長さ。
  84.     distance = (start_x - end_x).abs + (start_y - end_y).abs
  85.     # 描写開始
  86.     if end_color == start_color
  87.       for i in 1..distance
  88.         x = (start_x + (end_x - start_x) * i / distance).to_i
  89.         y = (start_y + (end_y - start_y) * i / distance).to_i
  90.         if width == 1
  91.           self.contents.set_pixel(x, y, start_color)
  92.         else
  93.           self.contents.fill_rect(x, y, width, width, start_color)
  94.         end
  95.       end
  96.     else
  97.       for i in 1..distance
  98.         x = (start_x + (end_x - start_x) * i / distance).to_i
  99.         y = (start_y + (end_y - start_y) * i / distance).to_i
  100.         r = start_color.red * (distance-i)/distance + end_color.red * i/distance
  101.         g = start_color.green * (distance-i)/distance + end_color.green * i/distance
  102.         b = start_color.blue * (distance-i)/distance + end_color.blue * i/distance
  103.         a = start_color.alpha * (distance-i)/distance + end_color.alpha * i/distance
  104.         if width == 1
  105.           self.contents.set_pixel(x, y, Color.new(r, g, b, a))
  106.         else
  107.           self.contents.fill_rect(x, y, width, width, Color.new(r, g, b, a))
  108.         end
  109.       end
  110.     end
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # ● HP的描画
  114.   #--------------------------------------------------------------------------
  115.   def draw_actor_hp_meter_line(actor, x, y, width = 156, height = 4)
  116.     w = width * actor.hp / actor.maxhp
  117.     hp_color_1 = Color.new(229, 188, 245, 255)
  118.     hp_color_2 = Color.new(171, 59, 245, 255)
  119.     i = 0
  120.     for i in 0..3
  121.      draw_line(x + width - w, y, x + width , y, hp_color_1, 1, hp_color_2)
  122.      y += 1
  123.      i += 1
  124.     end
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # ● SP的描画
  128.   #--------------------------------------------------------------------------
  129.   def draw_actor_sp_meter_line(actor, x, y, width = 156, height = 4)
  130.     w = width * actor.sp / actor.maxsp
  131.     sp_color_1 = Color.new( 245, 209, 187, 255)
  132.     sp_color_2 = Color.new( 250, 117, 65, 255)
  133.     for i in 0..3
  134.       draw_line(x + width - w, y, x + width , y, sp_color_1, 1, sp_color_2)
  135.       y += 1
  136.       i += 1
  137.     end
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # ● MP的描画
  141.   #--------------------------------------------------------------------------
  142.   def draw_actor_mp_meter_line(actor, x, y, width = 156, height = 4)
  143.     w = width * @actor_mp / @actor_maxmp
  144.     mp_color_1 = Color.new( 187, 225, 245, 255)
  145.     mp_color_2 = Color.new( 65, 193, 253, 255)
  146.     for i in 0..3
  147.       draw_line(x + width - w, y, x + width , y, mp_color_1, 1, mp_color_2)
  148.       y += 1
  149.       i += 1
  150.     end
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # ● 更新光标矩形
  154.   #--------------------------------------------------------------------------
  155.   def update_cursor_rect
  156.     # 光标位置不满 0 的情况下
  157.     if @index < 0 or self.active == false
  158.       @cursor.visible = false
  159.       return
  160.     end
  161.     @cursor.visible = true if self.visible && self.active
  162.     @cursor.opacitysz(1) if @cursor.opacity < 255
  163.     # 获取当前的行
  164.     row = @index / @column_max
  165.     # 当前行被显示开头行前面的情况下
  166.     if row < self.top_row
  167.       # 从当前行向开头行滚动
  168.       self.top_row = row
  169.     end
  170.     # 当前行被显示末尾行之后的情况下
  171.     if row > self.top_row + (self.page_row_max - 1)
  172.       # 从当前行向末尾滚动
  173.       self.top_row = row - (self.page_row_max - 1)
  174.     end
  175.     # 更新光标位置
  176.     @cursor.x = self.x + 128
  177.     @cursor.y = self.y + @index * 97 + 100
  178.   end
  179.   #--------------------------------------------------------------------------
  180.   # ● 刷新画面
  181.   #--------------------------------------------------------------------------
  182. def cursor_update
  183.    @cursor.update if @cursor.visible and @cursor.opacity == 255 and
  184.    self.active and @item_max >= 1
  185.    if self.active and @item_max > 0 and @index >= 0
  186.      index_var = @index
  187.      mouse_x, mouse_y = Mouse.get_mouse_pos
  188.      mouse_not_in_rect = true
  189.      for i in 0...@item_max
  190.        @index = i
  191.        update_cursor_rect
  192.        if (mouse_x > 565) and (mouse_y > 55 + i * 97) and
  193.           (mouse_x < 625) and (mouse_y < 135 + i * 97)
  194.          mouse_not_in_rect = false
  195.          $select[i] = true
  196.          if $refresh_variable == 0
  197.            $game_system.se_play($data_system.cursor_se)
  198.            refresh_face
  199.          end
  200.          $refresh_variable +=1
  201.          break
  202.        end
  203.      end
  204.      if mouse_not_in_rect
  205.        $refresh_variable = 0
  206.        @index = index_var
  207.        update_cursor_rect
  208.        for i in 0...@item_max
  209.          $select[i] = false
  210.        end
  211.        refresh_face
  212.        Mouse.click_lock
  213.      else
  214.        Mouse.click_unlock               
  215.      end
  216.    end
  217.    # 刷新光标矩形
  218.    update_cursor_rect
  219. end
  220.   
  221.   def dispose              
  222.     @cursor.dispose              
  223.     super                  
  224.   end
  225. end
复制代码


flyfairy于2011-5-10 14:23补充以下内容:
算了,我把它拆成两个窗口好了
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-11-25 21:28

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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