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

Project1

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

[讨论] 关于ESC菜单光标的问题

[复制链接]

Lv1.梦旅人

梦石
0
星屑
108
在线时间
1006 小时
注册时间
2008-11-9
帖子
1658
跳转到指定楼层
1
发表于 2012-4-4 17:20:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 判约之轮 于 2012-4-4 17:21 编辑

不知道该发在哪里,要说求具体代码也不是,要说求思路···总觉得如果能知道到底错在哪里的话,以后自己继续编写下去也容易得多了~
所以发在这个区了嗯,如果违反了版规的话,就请版主移动到提问区吧囧~

目前在做一个仿幻想三国志1的菜单系统,背景问题解决了,菜单位置问题也解决了,字体问题也解决了~
于是在光标暂时性置换问题上卡住了~

于是来求思路······
我原先的做法是在Window_Base里面将初始化函数第二行改为:
  1.   def initialize(x, y, width, height)
  2.     super
  3.     if $menu_open == false
  4.       self.windowskin = Cache.system("Window")
  5.     else
  6.       self.windowskin = Cache.system("Window2")
  7.     end
  8.     update_padding
  9.     update_tone
  10.     create_contents
  11.     @opening = @closing = false
  12.   end
复制代码
而Scence_MenuBase中重定义掉这些函数:
  1.   #--------------------------------------------------------------------------
  2.   # ● 开始处理
  3.   #--------------------------------------------------------------------------
  4.   def start
  5.     super
  6.     create_background
  7.     $menu_open = true
  8.     @actor = $game_party.menu_actor
  9.   end
  10.   #--------------------------------------------------------------------------
  11.   # ● 结束处理
  12.   #--------------------------------------------------------------------------
  13.   def terminate
  14.     super
  15.     dispose_background
  16.     $menu_open = false
  17.   end
  18.   #--------------------------------------------------------------------------
  19.   # ● 生成背景
  20.   #--------------------------------------------------------------------------
  21.   #def create_background
  22.   #  @background_sprite = Sprite.new
  23.   #  @background_sprite.bitmap = SceneManager.background_bitmap
  24.   #  @background_sprite.color.set(16, 16, 16, 128)
  25.   #end
  26.   #--------------------------------------------------------------------------
  27.   # ● 生成背景2
  28.   #--------------------------------------------------------------------------
  29.   def create_background
  30.     @menuback = Sprite.new
  31.     @menuback.bitmap = Bitmap.new("Graphics/Menu/background.png")
  32.     @menuback.x = 0
  33.     @menuback.y = 0
  34.     @menuback.z = 0
  35.     @menuback.opacity = 255
  36.     @menutext1 = Sprite.new
  37.     @menutext1.bitmap = Bitmap.new("Graphics/Menu/menutext1.png")
  38.     @menutext1.x = 0
  39.     @menutext1.y = 0
  40.     @menutext1.z = 2
  41.     @menutext1.opacity = 255
  42.     $menu_open = true
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # ● 释放背景
  46.   #--------------------------------------------------------------------------
  47.   def dispose_background
  48.     #@background_sprite.dispose
  49.     @menuback.dispose
  50.     @menutext1.dispose
  51.     $menu_open = false
  52.   end
复制代码
在Window_Command中,各种设置文字对齐的操作就不提了,那都是些无关紧要的东西~

我的整体思路是:
利用开关型变量,在ESC窗口开启时,自动把窗口皮肤切换到透明模式,只剩下选择框还保留着(已解决,另一个窗口皮肤用PS很容易弄出来)
在显示菜单的同时,将真正的菜单界面以图片的形式显示在最下层(即z = 0),文字作为单独的图片显示在第二层(z = 2),用来将选中的选项高亮显示的覆盖图片显示在第一层(z = 1)(已解决部分,第一层因为需要光标的配合还没解决)
调整选单窗口的坐标和文字间距,达到调整光标位置的效果(已解决)
调整头像等的坐标和缩放度,使其适应菜单背景(有思路,未解决)
其余下级菜单等预备以后再解决~

其实就是想问一下,到底怎么才能把矩形类的光标变为精灵类的图片呢?
我试过将显示和更新光标的函数重定义为精灵类的,可是一进入ESC菜单就报错~
大概是这一个函数:
  1.   #--------------------------------------------------------------------------
  2.   # ● 绘制内容
  3.   #     args : 与 Bitmap#draw_text 相同
  4.   #--------------------------------------------------------------------------
  5.   def draw_text(*args)
  6.     contents.draw_text(*args)
  7.   end
复制代码
但是我始终是不明白,我在我修改的脚本里并没有找到这个子函数,contents函数虽然有,但是也丝毫看不出怎么会出现错误提示中"5 for 3"(参数错误)这种情况~

顺便在下面贴上我在Window_Selectable中修改的函数:
  1.   #--------------------------------------------------------------------------
  2.   # ● 获取项目的绘制矩形
  3.   #--------------------------------------------------------------------------
  4.   def item_rect(index)
  5.     if $menu_open == false
  6.       rect = Rect.new
  7. #      if $menu_open == false
  8.         rect.width = item_width
  9. #      else
  10. #        rect.width = 44
  11. #      end
  12.       rect.height = item_height
  13.       rect.x = index % col_max * (item_width + spacing)
  14.       rect.y = index / col_max * item_height
  15.       rect
  16.     else
  17.       $rect = Sprite.new
  18.       $rect.bitmap = Bitmap.new("Graphics/Menu/menurect1.png")
  19.       $rect.x = index % col_max * (item_width + spacing)
  20.       $rect.y = index / col_max * item_height
  21.       $rect.z = 1
  22.       $rect
  23.     end
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● 获取项目的绘制矩形(内容用)
  27.   #--------------------------------------------------------------------------
  28.   def item_rect_for_text(index)
  29.       rect = item_rect(index)
  30.       if $menu_open = false
  31.         rect.x += 4
  32.         rect.width -= 8
  33.         rect
  34.       else
  35.         $rect.x += 4
  36.         $rect
  37.       end
  38.   end
复制代码
  1.   #--------------------------------------------------------------------------
  2.   # ● 更新光标
  3.   #--------------------------------------------------------------------------
  4.   def update_cursor
  5.     if $menu_open == false
  6.       if @cursor_all
  7.         cursor_rect.set(0, 0, contents.width, row_max * item_height)
  8.         self.top_row = 0
  9.       elsif @index < 0
  10.         cursor_rect.empty
  11.       else
  12.         ensure_cursor_visible
  13.         cursor_rect.set(item_rect(@index))
  14.       end
  15.     else
  16.       if @cursor_all
  17.         #cursor_rect.set(0, 0, contents.width, row_max * item_height)
  18.         $rect.x = 10
  19.         $rect.y = 105
  20.         $rect
  21.         self.top_row = 0
  22.       elsif @index < 0
  23.         cursor_rect.empty
  24.       else
  25.         ensure_cursor_visible
  26.         cursor_rect.set(item_rect(@index))
  27.       end
  28.     end
  29.   end
复制代码
  1.   #--------------------------------------------------------------------------
  2.   # ● 消除项目
  3.   #--------------------------------------------------------------------------
  4.   def clear_item(index)
  5.     #contents.clear_rect(item_rect(index))
  6.     $rect.dispose
  7.   end
复制代码

Lv1.梦旅人

Mr.Gandum

梦石
0
星屑
226
在线时间
2070 小时
注册时间
2007-1-31
帖子
3039

贵宾

2
发表于 2012-4-4 17:35:15 | 只看该作者
本帖最后由 feizhaodan 于 2012-4-4 17:40 编辑

1,sprite类没有contents这个属性。因该是bitmap
2,大概方法,就是将windowskin的光标部分取出到单独Bitmap,之后将Bitmap赋予Sprite,根据窗口Index改变位置。

其实我基本没看懂贴内说啥= =
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
108
在线时间
1006 小时
注册时间
2008-11-9
帖子
1658
3
 楼主| 发表于 2012-4-4 19:20:30 | 只看该作者
本帖最后由 判约之轮 于 2012-4-5 12:49 编辑
feizhaodan 发表于 2012-4-4 17:35
1,sprite类没有contents这个属性。因该是bitmap
2,大概方法,就是将windowskin的光标部分取出到单独Bitmap ...


果然····contents不是自定义函数而是内置函数····
抱歉刚才去点像素画没看到·····
于是我一会去试试嗯,多谢啦~

闪过来写一下最后的解决办法:
PHP 代码复制
  1. #--------------------------------------------------------------------------
  2.   # ● 获取项目的绘制矩形
  3.   #--------------------------------------------------------------------------
  4.   def item_rect(index)
  5.     if $menu_open == false
  6.       rect = Rect.new
  7.       rect.width = item_width
  8.       rect.height = item_height
  9.       rect.x = index % col_max * (item_width + spacing)
  10.       rect.y = index / col_max * item_height
  11.       rect
  12.     else
  13.       if $rect_if == true
  14.         $rectm.dispose
  15.       end
  16.       $rectm = Sprite.new
  17.       $rectm.bitmap = Bitmap.new("Graphics/Menu/menurect1.png")
  18.       temp1 = index % col_max * (item_width)
  19.       temp2 = index / col_max * item_height
  20.       rect = Rect.new(temp1, temp2, $rectm.bitmap.width, $rectm.bitmap.height)
  21.       #self.contents.blt(temp1, temp2, rectm.bitmap, rect)
  22.       $rectm.x = temp1 + 2
  23.       $rectm.y = temp2 + 118
  24.       $rect_if = true
  25.       rect.x = temp1
  26.       rect.y = temp2
  27.       rect
  28.     end
  29.   end


最终也没能完全改好,只能变通一下,通过精灵转矩形解决了~
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-27 10:21

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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