Project1
标题: 如何刷新窗口里的状态槽? [打印本页]
作者: tyq4590 时间: 2012-12-31 20:41
标题: 如何刷新窗口里的状态槽? 刚做了一个在地图上显示状态的窗口,在scene_map里也添加了显示和刷新的判定。现在的问题是,数据变更以后窗口里的数字会自动刷新,但是绘制的几个状态槽就直接消失了。希望大家帮我看看是怎么回事?窗口代码如下:
class Window_Mapstatus < Window_Base
#--------------------------------------------------------------------------
# ● 初始化窗口
#--------------------------------------------------------------------------
def initialize
@t = $game_variables [ 24 ]
super ( 27 , 0 , 800 , 46 )
self .contents = Bitmap.new ( width - 32 , height - 32 )
self .contents .font .size = 18
self .contents .font .color = normal_color
refresh
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self .contents .clear
self .contents .font .color = system_color
self .contents .font .size = 18
draw_stamina_bar( x+20 ,y,110 ,12 )
draw_hunger_bar( x+220 ,y,110 ,12 )
draw_mood_bar( x+420 ,y,110 ,12 )
draw_social_bar( x+620 ,y,110 ,12 )
self .contents .draw_text ( 50 ,-10 ,110 ,32 , $game_variables [ 86 ] .to_s )
self .contents .draw_text ( 250 ,-10 ,110 ,32 , $game_variables [ 87 ] .to_s )
self .contents .draw_text ( 450 ,-10 ,110 ,32 , $game_variables [ 88 ] .to_s )
self .contents .draw_text ( 650 ,-10 ,110 ,32 , $game_variables [ 89 ] .to_s )
end
#--------------------------------------------------------------------------
# ● 描绘体力槽
#--------------------------------------------------------------------------
def draw_stamina_bar( x, y, width = 110 , height = 4 )
stamina = $game_variables [ 86 ]
w = width * stamina / 100
hp_color_1 = Color.new ( 255 , 195 , 195 , 192 )
hp_color_2 = Color.new ( 195 , 180 , 255 , 192 )
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
x -= 1
y += ( height/4 ) .floor
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
end
#--------------------------------------------------------------------------
# ● 描绘饱食槽
#--------------------------------------------------------------------------
def draw_hunger_bar( x, y, width = 110 , height = 4 )
hunger = $game_variables [ 87 ]
w = width * hunger / 100
hp_color_1 = Color.new ( 255 , 195 , 195 , 192 )
hp_color_2 = Color.new ( 195 , 180 , 255 , 192 )
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
x -= 1
y += ( height/4 ) .floor
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
end
#--------------------------------------------------------------------------
# ● 描绘愉悦槽
#--------------------------------------------------------------------------
def draw_mood_bar( x, y, width = 110 , height = 4 )
mood = $game_variables [ 88 ]
w = width * mood / 100
hp_color_1 = Color.new ( 255 , 195 , 195 , 192 )
hp_color_2 = Color.new ( 195 , 180 , 255 , 192 )
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
x -= 1
y += ( height/4 ) .floor
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
end
#--------------------------------------------------------------------------
# ● 描绘社交槽
#--------------------------------------------------------------------------
def draw_social_bar( x, y, width = 110 , height = 4 )
social = $game_variables [ 89 ]
w = width * social / 100
hp_color_1 = Color.new ( 255 , 195 , 195 , 192 )
hp_color_2 = Color.new ( 195 , 180 , 255 , 192 )
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
x -= 1
y += ( height/4 ) .floor
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
end
end
class Window_Mapstatus < Window_Base
#--------------------------------------------------------------------------
# ● 初始化窗口
#--------------------------------------------------------------------------
def initialize
@t = $game_variables [ 24 ]
super ( 27 , 0 , 800 , 46 )
self .contents = Bitmap.new ( width - 32 , height - 32 )
self .contents .font .size = 18
self .contents .font .color = normal_color
refresh
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self .contents .clear
self .contents .font .color = system_color
self .contents .font .size = 18
draw_stamina_bar( x+20 ,y,110 ,12 )
draw_hunger_bar( x+220 ,y,110 ,12 )
draw_mood_bar( x+420 ,y,110 ,12 )
draw_social_bar( x+620 ,y,110 ,12 )
self .contents .draw_text ( 50 ,-10 ,110 ,32 , $game_variables [ 86 ] .to_s )
self .contents .draw_text ( 250 ,-10 ,110 ,32 , $game_variables [ 87 ] .to_s )
self .contents .draw_text ( 450 ,-10 ,110 ,32 , $game_variables [ 88 ] .to_s )
self .contents .draw_text ( 650 ,-10 ,110 ,32 , $game_variables [ 89 ] .to_s )
end
#--------------------------------------------------------------------------
# ● 描绘体力槽
#--------------------------------------------------------------------------
def draw_stamina_bar( x, y, width = 110 , height = 4 )
stamina = $game_variables [ 86 ]
w = width * stamina / 100
hp_color_1 = Color.new ( 255 , 195 , 195 , 192 )
hp_color_2 = Color.new ( 195 , 180 , 255 , 192 )
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
x -= 1
y += ( height/4 ) .floor
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
end
#--------------------------------------------------------------------------
# ● 描绘饱食槽
#--------------------------------------------------------------------------
def draw_hunger_bar( x, y, width = 110 , height = 4 )
hunger = $game_variables [ 87 ]
w = width * hunger / 100
hp_color_1 = Color.new ( 255 , 195 , 195 , 192 )
hp_color_2 = Color.new ( 195 , 180 , 255 , 192 )
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
x -= 1
y += ( height/4 ) .floor
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
end
#--------------------------------------------------------------------------
# ● 描绘愉悦槽
#--------------------------------------------------------------------------
def draw_mood_bar( x, y, width = 110 , height = 4 )
mood = $game_variables [ 88 ]
w = width * mood / 100
hp_color_1 = Color.new ( 255 , 195 , 195 , 192 )
hp_color_2 = Color.new ( 195 , 180 , 255 , 192 )
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
x -= 1
y += ( height/4 ) .floor
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
end
#--------------------------------------------------------------------------
# ● 描绘社交槽
#--------------------------------------------------------------------------
def draw_social_bar( x, y, width = 110 , height = 4 )
social = $game_variables [ 89 ]
w = width * social / 100
hp_color_1 = Color.new ( 255 , 195 , 195 , 192 )
hp_color_2 = Color.new ( 195 , 180 , 255 , 192 )
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
x -= 1
y += ( height/4 ) .floor
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .ceil , hp_color_2)
x -= 1
y += ( height/4 ) .ceil
draw_line( x, y, x + w, y, hp_color_1, ( height/4 ) .floor , hp_color_2)
end
end
作者: tyq4590 时间: 2013-1-1 16:43
试着把刷新改成连续刷新也不行,为什么draw_text就可以即时刷新而draw_line就不行呢?
作者: 羞射了 时间: 2013-1-1 17:19
你贴的这段看不出draw_line 是怎么定义的,draw_text能显示证明刷新显示没问题。可能问题出在draw_line
作者: tyq4590 时间: 2013-1-2 09:56
羞射了 发表于 2013-1-1 21:19
你贴的这段看不出draw_line 是怎么定义的,draw_text能显示证明刷新显示没问题。可能问题出在draw_line ...
draw_line的在这里:
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 + 1.0 * ( end_x - start_x) * i / distance) .to_i
y = ( start_y + 1.0 * ( 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 + 1.0 * ( end_x - start_x) * i / distance) .to_i
y = ( start_y + 1.0 * ( 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
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 + 1.0 * ( end_x - start_x) * i / distance) .to_i
y = ( start_y + 1.0 * ( 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 + 1.0 * ( end_x - start_x) * i / distance) .to_i
y = ( start_y + 1.0 * ( 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
作者: 羞射了 时间: 2013-1-2 11:45
哦,我略微看了下,问题可能还是出在第一篇里,
举个例子,我觉得以下的写法都可能会产生问题,比如:
draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
x -= 1
y += (height/4).floor
draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
x -= 1
y += (height/4).ceil
draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
x -= 1
y += (height/4).ceil
draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
不知道你是自己摸索的还是谁把你教坏了……
,因为你把drawline贴出来了,我试着重现了一下效果,我个人建议可以改成
for i in 0...height
draw_line(x-i+height, y+i, x-i+height+w, y+i, hp_color_1, 1, hp_color_2)
end
这样就ok
作者: tyq4590 时间: 2013-1-2 18:44
羞射了 发表于 2013-1-2 15:45
哦,我略微看了下,问题可能还是出在第一篇里,
举个例子,我觉得以下的写法都可能会产生问题,比如:
draw ...
多谢你的回答。我试了你说的方法,不过改完以后状态槽还是一刷新就消失。我发现切换到主菜单再切回地图就可以正常显示刷新后的状态槽了。我试了论坛里找的另外一个状态槽,还是同样的情况,所以我感觉应该跟状态槽这种显示方式有关?但是同样的状态槽在战斗场景下就工作正常。这是怎么回事呢?
附上另一个状态槽的代码:
# -----------------------------------------------------------------------------
# 值槽脚本随机生成系统(SLOTCR) By.Clov
# 通用版本:RMXP(RGSS1) RMVX(RGSS2) RMVX ACE(RGSS3)
# 使用方法:在全部窗口类插入即可 例:draw_cr(0,0,变量1,变量2,'开心值',100,10)
# 参数说明:x x坐标,y y坐标,current 当前值,max 最大值,txt 显示的文字
# width 值槽的宽,height 值槽的高
# 背景与边框没有随机的必要,请自行到脚本里设置
# -----------------------------------------------------------------------------
class Window_Base
def draw_cr( x,y,current,max,txt='' ,width=128 ,height=15 )
#颜色1、颜色2
c1=[ 59 , 191 , 119 ] ;c2=[ 253 , 94 , 1 ]
#边框色颜色
bk_color = Color.new ( 255 ,255 ,255 ,255 )
#数值是否显示
num = true
#显示数值的对齐方式 0:向左对齐 1:向中间对齐 2:向右边对齐
num_align = 1
#计算比率
bl = current.to_f / max
#计算实际宽
w = ( width*bl) .round
#描绘值槽
r = c1[ 0 ] ;g = c1[ 1 ] ;b = c1[ 2 ]
plus_r = ( c2[ 0 ] -c1[ 0 ] ) /( ( width-1 ) *bl)
plus_g = ( c2[ 1 ] -c1[ 1 ] ) /( ( width-1 ) *bl)
plus_b = ( c2[ 2 ] -c1[ 2 ] ) /( ( width-1 ) *bl)
w.times { |k|
contents.fill_rect ( x+k, y, 1 , height, Color.new ( r,g,b,255 ) )
r+=plus_r;g+=plus_g;b+=plus_b}
contents.fill_rect ( x-1 , y-1 , width+2 , 1 , bk_color)
contents.fill_rect ( x-1 , y+height, width+2 , 1 , bk_color)
contents.fill_rect ( x-1 , y, 1 , height, bk_color)
contents.fill_rect ( x+width, y, 1 , height, bk_color)
#描绘文字
txt_w = contents.text_size ( txt) .width + 2
contents.draw_text ( x-txt_w,y+height/2 -12 , width, 24 , txt)
contents.draw_text ( x,y+height/2 -12 , width, 24 ,
current.to_s +'/' +max.to_s ,num_align) if num
end
end
# -----------------------------------------------------------------------------
# 值槽脚本随机生成系统(SLOTCR) By.Clov
# 通用版本:RMXP(RGSS1) RMVX(RGSS2) RMVX ACE(RGSS3)
# 使用方法:在全部窗口类插入即可 例:draw_cr(0,0,变量1,变量2,'开心值',100,10)
# 参数说明:x x坐标,y y坐标,current 当前值,max 最大值,txt 显示的文字
# width 值槽的宽,height 值槽的高
# 背景与边框没有随机的必要,请自行到脚本里设置
# -----------------------------------------------------------------------------
class Window_Base
def draw_cr( x,y,current,max,txt='' ,width=128 ,height=15 )
#颜色1、颜色2
c1=[ 59 , 191 , 119 ] ;c2=[ 253 , 94 , 1 ]
#边框色颜色
bk_color = Color.new ( 255 ,255 ,255 ,255 )
#数值是否显示
num = true
#显示数值的对齐方式 0:向左对齐 1:向中间对齐 2:向右边对齐
num_align = 1
#计算比率
bl = current.to_f / max
#计算实际宽
w = ( width*bl) .round
#描绘值槽
r = c1[ 0 ] ;g = c1[ 1 ] ;b = c1[ 2 ]
plus_r = ( c2[ 0 ] -c1[ 0 ] ) /( ( width-1 ) *bl)
plus_g = ( c2[ 1 ] -c1[ 1 ] ) /( ( width-1 ) *bl)
plus_b = ( c2[ 2 ] -c1[ 2 ] ) /( ( width-1 ) *bl)
w.times { |k|
contents.fill_rect ( x+k, y, 1 , height, Color.new ( r,g,b,255 ) )
r+=plus_r;g+=plus_g;b+=plus_b}
contents.fill_rect ( x-1 , y-1 , width+2 , 1 , bk_color)
contents.fill_rect ( x-1 , y+height, width+2 , 1 , bk_color)
contents.fill_rect ( x-1 , y, 1 , height, bk_color)
contents.fill_rect ( x+width, y, 1 , height, bk_color)
#描绘文字
txt_w = contents.text_size ( txt) .width + 2
contents.draw_text ( x-txt_w,y+height/2 -12 , width, 24 , txt)
contents.draw_text ( x,y+height/2 -12 , width, 24 ,
current.to_s +'/' +max.to_s ,num_align) if num
end
end
作者: 羞射了 时间: 2013-1-2 19:09
tyq4590 发表于 2013-1-2 18:44
多谢你的回答。我试了你说的方法,不过改完以后状态槽还是一刷新就消失。我发现切换到主菜单再切回地图就 ...
那就可能是你scene_map调用的地方有问题了。
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1