赞 | 2 |
VIP | 0 |
好人卡 | 0 |
积分 | 4 |
经验 | 0 |
最后登录 | 2024-8-2 |
在线时间 | 62 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 440
- 在线时间
- 62 小时
- 注册时间
- 2023-7-16
- 帖子
- 20
|
本帖最后由 zlyl_wiley 于 2023-8-8 14:46 编辑
本来只想改一下天气随屏幕大小调整,结果捉到一只BUG,就是屏幕跟窗口大小不一致的情况下,画面冻结和过渡时会瞬间缩小的问题
目前解决方法就是自行Graphics#resize_screen一下
看config.rb里面似乎并没有读取屏幕的宽高,不清楚是在哪里读取的,郭大修一下吧
然后天气稍微改动了一下,根据屏幕大小,按原来的比例调整天气的范围和数量
没什么技术含量的东西,应该出不了什么问题
-----------
更新一下脚本:
# 屏幕大小改动过的话,目前需要先手动更新一下 Graphics.resize_screen(960, 720)
# 屏幕大小改动过的话,目前需要先手动更新一下
Graphics.resize_screen(960, 720)
# ------------------------------------------------------------------------------------------------- # RPG::Weather # ------------------------------------------------------------------------------------------------- module RPG class Weather MULTIPLE = (Graphics.width * Graphics.height) / 307200.0 # (640 * 480.0) PW = Graphics.width - 640 PH = Graphics.height - 480 SPRITE_MAX = (40 * MULTIPLE).to_i def initialize(viewport = nil) @type = 0 @max = 0 @ox = 0 @oy = 0 color1 = Color.new(255, 255, 255, 255) color2 = Color.new(255, 255, 255, 128) @rain_bitmap = Bitmap.new(7, 56) (0..6).each do |i| @rain_bitmap.fill_rect(6 - i, i * 8, 1, 8, color1) end @storm_bitmap = Bitmap.new(34, 64) (0..31).each do |i| @storm_bitmap.fill_rect(33 - i, i * 2, 1, 2, color2) @storm_bitmap.fill_rect(32 - i, i * 2, 1, 2, color1) @storm_bitmap.fill_rect(31 - i, i * 2, 1, 2, color2) end @snow_bitmap = Bitmap.new(6, 6) @snow_bitmap.fill_rect(0, 1, 6, 4, color2) @snow_bitmap.fill_rect(1, 0, 4, 6, color2) @snow_bitmap.fill_rect(1, 2, 4, 2, color1) @snow_bitmap.fill_rect(2, 1, 2, 4, color1) @sprites = [] (1..SPRITE_MAX).each do |_i| sprite = Sprite.new(viewport) sprite.z = 1000 sprite.visible = false sprite.opacity = 0 @sprites.push(sprite) end end def dispose @sprites.each do |sprite| sprite.dispose end @rain_bitmap.dispose @storm_bitmap.dispose @snow_bitmap.dispose end def type=(type) return if @type == type @type = type bitmap = case @type when 1 @rain_bitmap when 2 @storm_bitmap when 3 @snow_bitmap end (1..SPRITE_MAX).each do |i| sprite = @sprites[i] unless sprite.nil? sprite.visible = (i <= @max) sprite.bitmap = bitmap end end end def ox=(ox) return if @ox == ox @ox = ox @sprites.each do |sprite| sprite.ox = @ox end end def oy=(oy) return if @oy == oy @oy = oy @sprites.each do |sprite| sprite.oy = @oy end end def max=(max) return if @max == max @max = ([[max, 0].max, 40].min * MULTIPLE).to_i (1..SPRITE_MAX).each do |i| sprite = @sprites[i] sprite.visible = (i <= @max) unless sprite.nil? end end def update return if @type == 0 (1..@max).each do |i| sprite = @sprites[i] break if sprite.nil? if @type == 1 sprite.x -= 2 sprite.y += 16 sprite.opacity -= 8 end if @type == 2 sprite.x -= 8 sprite.y += 16 sprite.opacity -= 12 end if @type == 3 sprite.x -= 2 sprite.y += 8 sprite.opacity -= 8 end x = sprite.x - @ox y = sprite.y - @oy next unless (sprite.opacity < 64) || (x < -50) || (x > 750 + PW) || (y < -300) || (y > 500 + PH) sprite.x = rand(-50..(749 + PW)) + @ox sprite.y = rand(-200..(599 + PH)) + @oy sprite.opacity = 255 end end attr_reader :type, :max, :ox, :oy end end
# -------------------------------------------------------------------------------------------------
# RPG::Weather
# -------------------------------------------------------------------------------------------------
module RPG
class Weather
MULTIPLE = (Graphics.width * Graphics.height) / 307200.0 # (640 * 480.0)
PW = Graphics.width - 640
PH = Graphics.height - 480
SPRITE_MAX = (40 * MULTIPLE).to_i
def initialize(viewport = nil)
@type = 0
@max = 0
@ox = 0
@oy = 0
color1 = Color.new(255, 255, 255, 255)
color2 = Color.new(255, 255, 255, 128)
@rain_bitmap = Bitmap.new(7, 56)
(0..6).each do |i|
@rain_bitmap.fill_rect(6 - i, i * 8, 1, 8, color1)
end
@storm_bitmap = Bitmap.new(34, 64)
(0..31).each do |i|
@storm_bitmap.fill_rect(33 - i, i * 2, 1, 2, color2)
@storm_bitmap.fill_rect(32 - i, i * 2, 1, 2, color1)
@storm_bitmap.fill_rect(31 - i, i * 2, 1, 2, color2)
end
@snow_bitmap = Bitmap.new(6, 6)
@snow_bitmap.fill_rect(0, 1, 6, 4, color2)
@snow_bitmap.fill_rect(1, 0, 4, 6, color2)
@snow_bitmap.fill_rect(1, 2, 4, 2, color1)
@snow_bitmap.fill_rect(2, 1, 2, 4, color1)
@sprites = []
(1..SPRITE_MAX).each do |_i|
sprite = Sprite.new(viewport)
sprite.z = 1000
sprite.visible = false
sprite.opacity = 0
@sprites.push(sprite)
end
end
def dispose
@sprites.each do |sprite|
sprite.dispose
end
@rain_bitmap.dispose
@storm_bitmap.dispose
@snow_bitmap.dispose
end
def type=(type)
return if @type == type
@type = type
bitmap = case @type
when 1
@rain_bitmap
when 2
@storm_bitmap
when 3
@snow_bitmap
end
(1..SPRITE_MAX).each do |i|
sprite = @sprites[i]
unless sprite.nil?
sprite.visible = (i <= @max)
sprite.bitmap = bitmap
end
end
end
def ox=(ox)
return if @ox == ox
@ox = ox
@sprites.each do |sprite|
sprite.ox = @ox
end
end
def oy=(oy)
return if @oy == oy
@oy = oy
@sprites.each do |sprite|
sprite.oy = @oy
end
end
def max=(max)
return if @max == max
@max = ([[max, 0].max, 40].min * MULTIPLE).to_i
(1..SPRITE_MAX).each do |i|
sprite = @sprites[i]
sprite.visible = (i <= @max) unless sprite.nil?
end
end
def update
return if @type == 0
(1..@max).each do |i|
sprite = @sprites[i]
break if sprite.nil?
if @type == 1
sprite.x -= 2
sprite.y += 16
sprite.opacity -= 8
end
if @type == 2
sprite.x -= 8
sprite.y += 16
sprite.opacity -= 12
end
if @type == 3
sprite.x -= 2
sprite.y += 8
sprite.opacity -= 8
end
x = sprite.x - @ox
y = sprite.y - @oy
next unless (sprite.opacity < 64) || (x < -50) || (x > 750 + PW) || (y < -300) || (y > 500 + PH)
sprite.x = rand(-50..(749 + PW)) + @ox
sprite.y = rand(-200..(599 + PH)) + @oy
sprite.opacity = 255
end
end
attr_reader :type, :max, :ox, :oy
end
end
--------------
再来个变量版
这一版多了个resize(width, height)方法,在中途更改分辨率的时候,可以不中断天气地刷新天气的范围大小
经过频繁随机$game_screen.weather和resize测试,没测出毛病来,但对自己还是不太放心……
并且大概是在浪费时间,应该不会有人在游戏中途改分辨率吧!
# ------------------------------------------------------------------------------------------------- # RPG::Weather # ------------------------------------------------------------------------------------------------- module RPG class Weather def initialize(viewport = nil) @multiple = (Graphics.width * Graphics.height) / 307200.0 # (640 * 480.0) @pw = Graphics.width - 640 @ph = Graphics.height - 480 @max = (40 * @multiple).to_i @type = 0 @ox = 0 @oy = 0 color1 = Color.new(255, 255, 255, 255) color2 = Color.new(255, 255, 255, 128) @rain_bitmap = Bitmap.new(7, 56) (0..6).each do |i| @rain_bitmap.fill_rect(6 - i, i * 8, 1, 8, color1) end @storm_bitmap = Bitmap.new(34, 64) (0..31).each do |i| @storm_bitmap.fill_rect(33 - i, i * 2, 1, 2, color2) @storm_bitmap.fill_rect(32 - i, i * 2, 1, 2, color1) @storm_bitmap.fill_rect(31 - i, i * 2, 1, 2, color2) end @snow_bitmap = Bitmap.new(6, 6) @snow_bitmap.fill_rect(0, 1, 6, 4, color2) @snow_bitmap.fill_rect(1, 0, 4, 6, color2) @snow_bitmap.fill_rect(1, 2, 4, 2, color1) @snow_bitmap.fill_rect(2, 1, 2, 4, color1) @sprites = [] (1..@max).each do |_i| sprite = Sprite.new(viewport) sprite.z = 1000 sprite.visible = false sprite.opacity = 0 @sprites.push(sprite) end end def resize(width, height) @multiple = (width * height) / 307200.0 # (640 * 480.0) @pw = width - 640 @ph = height - 480 @max = (40 * @multiple).to_i if @max == @sprites.size return elsif @max < @sprites.size (@max...@sprites.size).each do |i| @sprites[i].visible = false end else bitmap = case @type when 1 @rain_bitmap when 2 @storm_bitmap when 3 @snow_bitmap end viewport = @sprites[0].viewport (@sprites.size..@max).each do |_i| sprite = Sprite.new(viewport) sprite.z = 1000 sprite.bitmap = bitmap @sprites.push(sprite) end end end def dispose @sprites.each do |sprite| sprite.dispose end @rain_bitmap.dispose @storm_bitmap.dispose @snow_bitmap.dispose end def type=(type) return if @type == type @type = type bitmap = case @type when 1 @rain_bitmap when 2 @storm_bitmap when 3 @snow_bitmap end (0..[@max, @sprites.size].max).each do |i| sprite = @sprites[i] unless sprite.nil? sprite.visible = (i <= @max) sprite.bitmap = bitmap end end end def ox=(ox) return if @ox == ox @ox = ox @sprites.each do |sprite| sprite.ox = @ox end end def oy=(oy) return if @oy == oy @oy = oy @sprites.each do |sprite| sprite.oy = @oy end end def max=(max) return if @max == (max * @multiple).to_i last = @max @max = ([[max, 0].max, 40].min * @multiple).to_i ([last, @max].min...@sprites.size).each do |i| @sprites[i].visible = (i <= @max) end end def update return if @type == 0 (0..@max).each do |i| sprite = @sprites[i] break if sprite.nil? if @type == 1 sprite.x -= 2 sprite.y += 16 sprite.opacity -= 8 end if @type == 2 sprite.x -= 8 sprite.y += 16 sprite.opacity -= 12 end if @type == 3 sprite.x -= 2 sprite.y += 8 sprite.opacity -= 8 end x = sprite.x - @ox y = sprite.y - @oy next unless (sprite.opacity < 64) || (x < -50) || (x > 750 + @pw) || (y < -300) || (y > 500 + @ph) sprite.x = rand(-50..(749 + @pw)) + @ox sprite.y = rand(-200..(599 + @ph)) + @oy sprite.opacity = 255 end end attr_reader :type, :max, :ox, :oy end end
# -------------------------------------------------------------------------------------------------
# RPG::Weather
# -------------------------------------------------------------------------------------------------
module RPG
class Weather
def initialize(viewport = nil)
@multiple = (Graphics.width * Graphics.height) / 307200.0 # (640 * 480.0)
@pw = Graphics.width - 640
@ph = Graphics.height - 480
@max = (40 * @multiple).to_i
@type = 0
@ox = 0
@oy = 0
color1 = Color.new(255, 255, 255, 255)
color2 = Color.new(255, 255, 255, 128)
@rain_bitmap = Bitmap.new(7, 56)
(0..6).each do |i|
@rain_bitmap.fill_rect(6 - i, i * 8, 1, 8, color1)
end
@storm_bitmap = Bitmap.new(34, 64)
(0..31).each do |i|
@storm_bitmap.fill_rect(33 - i, i * 2, 1, 2, color2)
@storm_bitmap.fill_rect(32 - i, i * 2, 1, 2, color1)
@storm_bitmap.fill_rect(31 - i, i * 2, 1, 2, color2)
end
@snow_bitmap = Bitmap.new(6, 6)
@snow_bitmap.fill_rect(0, 1, 6, 4, color2)
@snow_bitmap.fill_rect(1, 0, 4, 6, color2)
@snow_bitmap.fill_rect(1, 2, 4, 2, color1)
@snow_bitmap.fill_rect(2, 1, 2, 4, color1)
@sprites = []
(1..@max).each do |_i|
sprite = Sprite.new(viewport)
sprite.z = 1000
sprite.visible = false
sprite.opacity = 0
@sprites.push(sprite)
end
end
def resize(width, height)
@multiple = (width * height) / 307200.0 # (640 * 480.0)
@pw = width - 640
@ph = height - 480
@max = (40 * @multiple).to_i
if @max == @sprites.size
return
elsif @max < @sprites.size
(@max...@sprites.size).each do |i|
@sprites[i].visible = false
end
else
bitmap = case @type
when 1
@rain_bitmap
when 2
@storm_bitmap
when 3
@snow_bitmap
end
viewport = @sprites[0].viewport
(@sprites.size..@max).each do |_i|
sprite = Sprite.new(viewport)
sprite.z = 1000
sprite.bitmap = bitmap
@sprites.push(sprite)
end
end
end
def dispose
@sprites.each do |sprite|
sprite.dispose
end
@rain_bitmap.dispose
@storm_bitmap.dispose
@snow_bitmap.dispose
end
def type=(type)
return if @type == type
@type = type
bitmap = case @type
when 1
@rain_bitmap
when 2
@storm_bitmap
when 3
@snow_bitmap
end
(0..[@max, @sprites.size].max).each do |i|
sprite = @sprites[i]
unless sprite.nil?
sprite.visible = (i <= @max)
sprite.bitmap = bitmap
end
end
end
def ox=(ox)
return if @ox == ox
@ox = ox
@sprites.each do |sprite|
sprite.ox = @ox
end
end
def oy=(oy)
return if @oy == oy
@oy = oy
@sprites.each do |sprite|
sprite.oy = @oy
end
end
def max=(max)
return if @max == (max * @multiple).to_i
last = @max
@max = ([[max, 0].max, 40].min * @multiple).to_i
([last, @max].min...@sprites.size).each do |i|
@sprites[i].visible = (i <= @max)
end
end
def update
return if @type == 0
(0..@max).each do |i|
sprite = @sprites[i]
break if sprite.nil?
if @type == 1
sprite.x -= 2
sprite.y += 16
sprite.opacity -= 8
end
if @type == 2
sprite.x -= 8
sprite.y += 16
sprite.opacity -= 12
end
if @type == 3
sprite.x -= 2
sprite.y += 8
sprite.opacity -= 8
end
x = sprite.x - @ox
y = sprite.y - @oy
next unless (sprite.opacity < 64) || (x < -50) || (x > 750 + @pw) || (y < -300) || (y > 500 + @ph)
sprite.x = rand(-50..(749 + @pw)) + @ox
sprite.y = rand(-200..(599 + @ph)) + @oy
sprite.opacity = 255
end
end
attr_reader :type, :max, :ox, :oy
end
end
|
|