加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 你最珍贵 于 2014-4-5 17:48 编辑
#============================================================================== # ■ Graphics #------------------------------------------------------------------------------ # 可以提示所有文本,支持所有场景显示。 #------------------------------------------------------------------------------ # 作者:你最珍贵 # 日期:2014-4-5 17:23 # 使用方法:Graphics.tips("") # 版权说明:转载请保留作者信息,谢谢。 #============================================================================== class << Graphics #-------------------------------------------------------------------------- # ● 常量定义 #-------------------------------------------------------------------------- Tips_width = 640 # 底图宽度 Tips_height = 32 # 底图高度 Tips_ShowTime = 60 # 显示时间(最小35,最大不限) Tips_Color = Color.new(0,0,0,220) # 底图颜色 #--------------------------------------------------------------------------- # ● 提示文本 #--------------------------------------------------------------------------- def tips(text, x = 0, y = 0, color = Color.new(238, 255, 64)) y = (640 - Tips_height) / 2 - 132 if y == 0 x = (480 - Tips_width) / 2 if x == 0 tips_create_bitmap(x, y) tips_draw_text(text, color) @tips_sprite.opacity = 255 @tips_time = Tips_ShowTime end #--------------------------------------------------------------------------- # ● 提示文本 #--------------------------------------------------------------------------- def tips_draw_text(text, color) @tips_bitmap.font.size = 25 @tips_bitmap.font.color = color cw = @tips_bitmap.text_size(text).width @tips_bitmap.fill_rect(0,0,Tips_width, Tips_height,Tips_Color) @tips_bitmap.draw_text(0,0,Tips_width,Tips_height,text,1) end #--------------------------------------------------------------------------- # ● 创建精灵位图 #--------------------------------------------------------------------------- def tips_create_bitmap(x, y) if @tips_sprite.nil? or @tips_sprite.disposed? @tips_sprite = Sprite.new @tips_sprite.z = 9999 @tips_bitmap = Bitmap.new(Tips_width, Tips_height) @tips_sprite.bitmap = @tips_bitmap end @tips_sprite.x, @tips_sprite.y = x, y end #--------------------------------------------------------------------------- # ● 刷新提示信息 #--------------------------------------------------------------------------- alias tips_update update def update tips_update unless @tips_sprite.nil? or @tips_sprite.disposed? if @tips_time and @tips_time > 0 @tips_sprite.opacity -= 8 if @tips_time <= 35 @tips_time -= 1 end end end end
#==============================================================================
# ■ Graphics
#------------------------------------------------------------------------------
# 可以提示所有文本,支持所有场景显示。
#------------------------------------------------------------------------------
# 作者:你最珍贵
# 日期:2014-4-5 17:23
# 使用方法:Graphics.tips("")
# 版权说明:转载请保留作者信息,谢谢。
#==============================================================================
class << Graphics
#--------------------------------------------------------------------------
# ● 常量定义
#--------------------------------------------------------------------------
Tips_width = 640 # 底图宽度
Tips_height = 32 # 底图高度
Tips_ShowTime = 60 # 显示时间(最小35,最大不限)
Tips_Color = Color.new(0,0,0,220) # 底图颜色
#---------------------------------------------------------------------------
# ● 提示文本
#---------------------------------------------------------------------------
def tips(text, x = 0, y = 0, color = Color.new(238, 255, 64))
y = (640 - Tips_height) / 2 - 132 if y == 0
x = (480 - Tips_width) / 2 if x == 0
tips_create_bitmap(x, y)
tips_draw_text(text, color)
@tips_sprite.opacity = 255
@tips_time = Tips_ShowTime
end
#---------------------------------------------------------------------------
# ● 提示文本
#---------------------------------------------------------------------------
def tips_draw_text(text, color)
@tips_bitmap.font.size = 25
@tips_bitmap.font.color = color
cw = @tips_bitmap.text_size(text).width
@tips_bitmap.fill_rect(0,0,Tips_width, Tips_height,Tips_Color)
@tips_bitmap.draw_text(0,0,Tips_width,Tips_height,text,1)
end
#---------------------------------------------------------------------------
# ● 创建精灵位图
#---------------------------------------------------------------------------
def tips_create_bitmap(x, y)
if @tips_sprite.nil? or @tips_sprite.disposed?
@tips_sprite = Sprite.new
@tips_sprite.z = 9999
@tips_bitmap = Bitmap.new(Tips_width, Tips_height)
@tips_sprite.bitmap = @tips_bitmap
end
@tips_sprite.x, @tips_sprite.y = x, y
end
#---------------------------------------------------------------------------
# ● 刷新提示信息
#---------------------------------------------------------------------------
alias tips_update update
def update
tips_update
unless @tips_sprite.nil? or @tips_sprite.disposed?
if @tips_time and @tips_time > 0
@tips_sprite.opacity -= 8 if @tips_time <= 35
@tips_time -= 1
end
end
end
end
可以提示所有文本,支持所有场景显示。 |