| 赞 | 12 |
| VIP | |
| 好人卡 | |
| 积分 | 28 |
| 经验 | |
| 最后登录 | 2024-1-27 |
| 在线时间 | 585 小时 |
- 梦石
- 0
- 星屑
- 2821
- 在线时间
- 585 小时
- 注册时间
- 2022-7-13
- 回帖
- 81
|
发表于 2022-11-16 19:32:56
|
显示全部楼层
本帖最后由 我为鱼肉 于 2022-11-18 12:58 编辑
做了个简单的范例
网游式全场景提示窗口.zip
(986.41 KB, 下载次数: 7)
GIF预览
代码- #==============================================================================
- # ** RPG::Cache 高速缓存UI
- #==============================================================================
- module RPG::Cache
- def self.ui(filename)
- self.load_bitmap("Graphics/UI/", filename)
- end
- end
- #==============================================================================
- # ** Bitmap 拓展
- #==============================================================================
- class Bitmap
- #--------------------------------------------------------------------------
- # * draw_windowskin 描绘窗口皮肤
- # window_x 窗口X坐标 默认0
- # window_Y 窗口Y坐标 默认0
- # window_width 窗口width 默认self.width
- # window_height 窗口height 默认self.height
- #--------------------------------------------------------------------------
- def draw_windowskin(window_x = 0, window_y = 0, window_width = self.width, window_height = self.height)
- src_bitmap = RPG::Cache.ui("帮助窗口背景.png")
- src_rect = Rect.new(0, 0, 0, 0)
- dest_rect = Rect.new(0, 0, 0, 0)
- #上
- src_rect.set(0, 0, 5, 5)
- self.blt(window_x, window_y, src_bitmap, src_rect)
- src_rect.set(6, 0, 5, 5)
- self.blt(window_x + window_width - 5, window_y, src_bitmap, src_rect)
- dest_rect.set(window_x + 5, window_y, window_width - 10, 5)
- src_rect.set(5, 0, 1, 5)
- self.stretch_blt(dest_rect, src_bitmap, src_rect)
- #下
- src_rect.set(0, 6, 5, 5)
- self.blt(window_x, window_y + window_height - 5, src_bitmap, src_rect)
- src_rect.set(6, 6, 5, 5)
- self.blt(window_x + window_width - 5, window_y + window_height - 5, src_bitmap, src_rect)
- dest_rect.set(window_x + 5, window_y + window_height - 5, window_width - 10, 5)
- src_rect.set(5, 6, 1, 5)
- self.stretch_blt(dest_rect, src_bitmap, src_rect)
- #其余
- dest_rect.set(window_x, window_y + 5, 5, window_height - 10)
- src_rect.set(0, 5, 5, 1)
- self.stretch_blt(dest_rect, src_bitmap, src_rect)
- dest_rect.set(window_x + window_width - 5, window_y + 5, 5, window_height - 10)
- src_rect.set(6, 5, 5, 1)
- self.stretch_blt(dest_rect, src_bitmap, src_rect)
- dest_rect.set(window_x + 5, window_y + 5, window_width - 10, window_height - 10)
- src_rect.set(5, 5, 1, 1)
- self.stretch_blt(dest_rect, src_bitmap, src_rect)
- end
- end
- #bitmap.draw_windowskin描绘测试
- #sprite = Sprite.new
- #sprite.bitmap = Bitmap.new(640, 480)
- #sprite.bitmap.draw_windowskin(160, 226, 320, 28)
- #loop do
- # Graphics.update
- #end
- #==============================================================================
- # ** Sprite 提示窗口
- #==============================================================================
- class Wwyr_Tips < Sprite
- #--------------------------------------------------------------------------
- # * initialize 初始化
- # x X坐标
- # y Y坐标
- # text 文本
- # viewport 视口 默认nil
- #--------------------------------------------------------------------------
- def initialize(x, y, text, viewport = nil)
- super(viewport)
- self.z = 99999
- self.x = x
- self.y = y
- self.bitmap = Bitmap.new(320, 28) ##窗口大小
- self.bitmap.font.size = 16 ##字体大小
- self.bitmap.draw_windowskin
- self.bitmap.draw_text(4, 0, self.bitmap.width, self.bitmap.height, text)
- @count = 60 ##提示窗口展示的时间(刷新次数)
- end
- #--------------------------------------------------------------------------
- # * update 刷新
- #--------------------------------------------------------------------------
- def update
- if @count > 0
- @count -= 1
- else
- self.visible = false
- end
- super
- end
- end
- #==============================================================================
- # ** Graphics 提示窗口《操作库》
- #==============================================================================
- class << Graphics
- #--------------------------------------------------------------------------
- # * tip_init 初始化
- #--------------------------------------------------------------------------
- def tip_init
- @tips = [] ##精灵
- @text = [] ##tips文本的数组
- @count = 0 ##tips计数
- end
- #--------------------------------------------------------------------------
- # * tip 提示(单个)
- # text 文本
- #--------------------------------------------------------------------------
- def tip(text)
- for i in 0...@tips.size
- @tips[i].y = 226 - (@tips.size - i) * 14
- end
- tip = Wwyr_Tips.new(160, 226, text)
- @tips.push(tip)
- end
- #--------------------------------------------------------------------------
- # * tips 提示(同时、多个)
- # text 文本数组
- # frame 间隔帧数 默认4
- #--------------------------------------------------------------------------
- def tips(text, frame = 4)
- @text = @text | text
- @count = 0
- @frame = frame
- end
- #--------------------------------------------------------------------------
- # * update 刷新
- #--------------------------------------------------------------------------
- alias wwyralias_update_for_tips update unless method_defined? :wwyralias_update_for_tips
- def update
- if @text.size > 0
- if @count == 0
- text = @text.shift
- tip(text)
- @count = @frame
- else
- @count -= 1
- end
- end
- clear_data = false
- for i in 0...@tips.size
- @tips[i].update
- unless @tips[i].visible
- @tips[i].dispose
- @tips[i] = nil
- clear_data = true
- end
- end
- @tips.compact! if clear_data
- wwyralias_update_for_tips
- end
- end
- Graphics.tip_init
- #代码测试
- loop do
- Graphics.tips(["0", "1", "2"]) if Graphics.frame_count % 9 == 0
- #Graphics.tip(Graphics.frame_count.to_s) if Graphics.frame_count % 4 == 0
- Graphics.update
- end
复制代码 |
评分
-
查看全部评分
|