| 赞 | 0 |
| VIP | |
| 好人卡 | |
| 积分 | 1 |
| 经验 | |
| 最后登录 | 2014-9-6 |
| 在线时间 | 2 小时 |
- 梦石
- 1
- 星屑
- 602
- 在线时间
- 2 小时
- 注册时间
- 2010-11-1
- 回帖
- 1
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 xmttttt 于 2014-9-6 11:31 编辑
【学习Ruby三天】一个很渣的Sprite浮动文字系统
受到了Yuee的地图名显示脚本的启发
https://rpg.blue/thread-282895-1-1.html
但是他做的是window,如果遇到要直接浮动文字,不想有边框的情况怎么办呢?
虽然也有把窗框背景设为全透明的方法可选,但感觉是不是有点脱裤子放屁
然后就想能不能直接用Sprite显示浮动文字,于是就做了这个。{:2_275:}
刚学ruby,请轻喷{:2_277:}
ps:第一次认真使用RPGMaker的脚本编辑器,感觉功能还是很强大的。就算用不着我这个显示文字的功能,把我代码拿去改改显示个图像什么的也完全是没有问题{:2_274:}
使用说明&效果示意:
更新日志:
v0.65 aleph
v0.9 beth 修正了语法错误,添加了改变字体的功能
[pre lang="ruby" line="1" file="MyFloatingText"]#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# RPGMaker VX Sprite浮动文字系统 by Spacesoft
# 本系统用于在RPGMaker VX环境下方便快捷地产生浮动文字。所生成的浮动文字为
# Sprite的子类,并提供一个Scene_Base类下的方法快捷产生浮动文字。支持浮现、
# 渐隐和移动。目前暂时只能显示单行字符,其他功能还在开发中~
# 输入字符支持“/字母[数字]"格式的一些属性设定,具体见函数说明。
#
# - MyFloatingText
#------------------------------------------------------------------------------
# 浮动文字类
# 版本:0.9 beth
# 作者:Spacesoft
#------------------------------------------------------------------------------
# 全部文件:
# ┗★MyFloatingText
# ┗ MyTempFloatingText
# ┗ MyScene_Base
#
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
class MyFloatingText < Sprite
#--------------------------------------------------------------------------
# * 物件初始化
# x : 視窗X座標
# y : 視窗Y座標
# text : 要显示的文字内容
# 属性设定字:
# 字号设定/p[n]
# 颜色设定/c[n]
# 粗体设定/b[n]:0为普通,1为斜体,其它无效
# 斜体设定/i[n]:0为普通,1为斜体,其它无效
# 阴影设定/s[n]:0为无阴影,1为有阴影,其它无效
# 字体设定/f[n]
# 字符"/"被用作转义符,想要显示"/"请输入"//"
# 暂不支持换行符,不能多行显示
# 示例:$scene.floating_text(100,100,"示例/c[2]文/p[50]字",0,0,100,1)
#--------------------------------------------------------------------------
def initialize(x,y,text)
super()
self.x=x
self.y=y
#计算bitmap的大小,因此只需要对字号大小进行判断
text_copy=text.downcase
dummy_bitmap=Bitmap.new(1,1)
size_x=0
size_y=0
while text_copy!=""
if text_copy.slice!(/^\/([pcbisf])\[([0-9]+)\]/)!=nil #匹配成功
case $1
when "p" #是字号设定\\p[n]
dummy_bitmap.font.size=$2.to_i
else
end
elsif text_copy.slice!(/^\/\//)!=nil #字符"//"变为"/"
size_x+=dummy_bitmap.text_size("/").width
if dummy_bitmap.text_size("/").height>size_y
size_y=dummy_bitmap.text_size("/").height
else
end
elsif text_copy.slice!(/^\//)!=nil #字符"/"消掉
else #普通字符
text_copy.slice!(/^(.)/) #削下一个字符
size_x+=dummy_bitmap.text_size($1).width
if dummy_bitmap.text_size($1).height>size_y
size_y=dummy_bitmap.text_size($1).height
else
end
end
end
dummy_bitmap.dispose
#按照上面求出的大小绘制Bitmap
text_copy=text.downcase
text_bitmap=Bitmap.new(size_x,size_y)
#字符转义
#判断是否为字号设定/p[n]
#判断是否为颜色设定/c[n]
#判断是否为粗体设定/b[n]
#判断是否为斜体设定/i[n]
#判断是否为阴影设定/s[n]
now_start_x=0 #目前x坐标起始位置
now_start_y=0 #目前y坐标起始位置
while text_copy!=""
if text_copy.slice!(/^\/([pcbisf])\[([0-9]+)\]/)!=nil #匹配成功
case $1
when "p" #是字号设定/p[n]
text_bitmap.font.size=$2.to_i
when "c" #是颜色设定/c[n]
text_bitmap.font.color=text_color($2.to_i)
when "b" #是粗体设定/b[n]
case $2.to_i
when 0
text_bitmap.font.bold=false
when 1
text_bitmap.font.bold=true
else
end
when "i" #是斜体设定/i[n]
case $2.to_i
when 0
text_bitmap.font.italic=false
when 1
text_bitmap.font.italic=true
else
end
when "s" #是阴影设定/s[n]
case $2.to_i
when 0
text_bitmap.font.shadow=false
when 1
text_bitmap.font.shadow=true
else
end
when "f" #是字体设定/f[n]
if Font.default_name[$2.to_i]!=nil
text_bitmap.font.name=Font.default_name[$2.to_i]
end
else
end
elsif text_copy.slice!(/^\/\//)!=nil #字符"//"变为"/"
char_width=text_bitmap.text_size("/").width
char_height=text_bitmap.text_size("/").height
text_bitmap.draw_text(now_start_x,size_y-char_height,char_width,char_height,"/",0)
now_start_x+=char_width
elsif text_copy.slice!(/^\//)!=nil #字符"/"消掉
else #普通字符
text_copy.slice!(/^(.)/) #削下一个字符
char_width=text_bitmap.text_size($1).width
char_height=text_bitmap.text_size($1).height
text_bitmap.draw_text(now_start_x,size_y-char_height,char_width,char_height,$1,0)
now_start_x+=char_width
end
#p text_copy
#text_bitmap.draw_text(100,0,10,20,"i",0)
end
#text_bitmap.draw_text(100,0,10,20,"i",0)
self.bitmap=text_bitmap
#self.bitmap = @animation_bitmap1
end
def text_color(n)
x = 64 + (n % 8) * 8
y = 96 + (n / 8) * 8
windowskin = Cache.system("Window")
return windowskin.get_pixel(x, y)
end
end[/pre]
[pre lang="ruby" line="1" file="MyTempFloatingText"]#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# RPGMaker VX Sprite浮动文字系统 by Spacesoft
# 本系统用于在RPGMaker VX环境下方便快捷地产生浮动文字。所生成的浮动文字为
# Sprite的子类,并提供一个Scene_Base类下的方法快捷产生浮动文字。支持浮现、
# 渐隐和移动。目前暂时只能显示单行字符,其他功能还在开发中~
# 输入字符支持“/字母[数字]"格式的一些属性设定,具体见函数说明。
#
# - MyTempFloatingText
#------------------------------------------------------------------------------
# 高级的浮动文字类,支持浮现、渐隐和运动
# 版本:0.9 beth
# 作者:Spacesoft
#------------------------------------------------------------------------------
# 全部文件:
# ┗ MyFloatingText
# ┗★MyTempFloatingText
# ┗ MyScene_Base
#
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
class MyTempFloatingText < MyFloatingText
attr_accessor:birth_time
attr_accessor:hold_time
attr_accessor:fade_time
attr_accessor:existence_time #已经存在了的时间
attr_accessor:velocity #浮动文字的运动速度,每帧移动的像素数
attr_accessor:direction #浮动文字的运动方向,角度制。0为正北,逆时针旋转
attr_accessor:x_f #x坐标的浮点版本,以防误差
attr_accessor:y_f #y坐标的浮点版本,以防误差
include Math
def initialize(x,y,text,birth_time=10,hold_time=100,fade_time=10,velocity=0,direction=0)
super(x,y,text)
@birth_time=birth_time
@hold_time=hold_time
@fade_time=fade_time
@velocity=velocity
@direction=direction
@existence_time=0
@x_f=x
@y_f=y
end
def linear_move #浮动文字线性运动一帧。
if self.velocity!=0
real_rad_dir=(self.direction.to_f+90)*PI/180 #角度转换为弧度并加90度修正
self.x_f=self.x_f+self.velocity*cos(real_rad_dir)
self.y_f=self.y_f-self.velocity*sin(real_rad_dir)
self.x=self.x_f.to_i
self.y=self.y_f.to_i
end
end
end[/pre]
[pre lang="ruby" line="1" file="MyScene_Base"]#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# RPGMaker VX Sprite浮动文字系统 by Spacesoft
# 本系统用于在RPGMaker VX环境下方便快捷地产生浮动文字。所生成的浮动文字为
# Sprite的子类,并提供一个Scene_Base类下的方法快捷产生浮动文字。支持浮现、
# 渐隐和移动。目前暂时只能显示单行字符,其他功能还在开发中~
# 输入字符支持“/字母[数字]"格式的一些属性设定,具体见函数说明。
#
# - MyScene_Base
#------------------------------------------------------------------------------
# 增强Scene_Base类,添加对高级浮动文字的支持
# 版本:0.9 beth
# 作者:Spacesoft
#------------------------------------------------------------------------------
# 全部文件:
# ┗ MyFloatingText
# ┗ MyTempFloatingText
# ┗★MyScene_Base
#
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
class Scene_Base
include Math
alias base_start start
def start
base_start
@ft_array=[] #存放浮动文字的数组
end
def floating_text(x,y,text,birth_time=10,hold_time=100,fade_time=10,velocity=0,direction=0)
new_text=MyTempFloatingText.new(x,y,text,birth_time,hold_time,fade_time,velocity,direction)
@ft_array.push(new_text)
end
alias base_update update
def update
base_update
update_floating_text
end
alias base_pt pre_terminate
def pre_terminate
base_pt
@ft_array.each do |i|
i.dispose
end
@ft_array.clear
end
def update_floating_text
@ft_array.each do |i|
i.existence_time+=1 #已存在时间时间+=1
case i.existence_time
when 1 .. i.birth_time
i.opacity=(i.existence_time.to_f/i.birth_time*255).to_i
i.linear_move #线性移动一帧
when i.birth_time+1 .. i.birth_time+i.hold_time
i.opacity=255
i.linear_move #线性移动一帧
when i.birth_time+i.hold_time+1 .. i.birth_time+i.hold_time+i.fade_time
i.opacity=((i.birth_time.to_f+i.hold_time+i.fade_time-i.existence_time)/i.fade_time*255).to_i
i.linear_move #线性移动一帧
else
@ft_array.delete(i).dispose
end
end
end
end[/pre] |
评分
-
查看全部评分
|