#============================================================================
# ■ Plane
#============================================================================
class Plane
#--------------------------------------------------------------------------
# ● 初始化定义
#--------------------------------------------------------------------------
def initialize(viewport = nil)
@x = 0
@y = 0
@z = 0
@ox = 0
@oy = 0
@ox2 = 0
@oy2 = 0
@rect = viewport ? viewport.rect : Rect.new(0, 0, 800, 600) # 改成游戏分辨率(0, 0, 宽, 高)
@zoom_x = 1.0
@zoom_y = 1.0
@bitmap = nil
@contents = Sprite.new(viewport)
@n_w = 1
@n_h = 1
@visible = true
@tone = Tone.new(0, 0, 0, 0)
@color = Color.new(255,255,255,0)
@blend_type = 0
@opacity = 255
@disposed = false
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def update
@contents.x = @x
@contents.y = @y
@contents.ox = @ox2
@contents.oy = @oy2
@contents.opacity = @opacity
@contents.visible = @visible
@contents.color = @color
@contents.tone = @tone
@contents.blend_type = @blend_type
@contents.z = @z
end
#--------------------------------------------------------------------------
# ● 装载图形(bitmap)
#--------------------------------------------------------------------------
def bitmap=(bitmap)
if @disposed
raise(RGSSError,"disposed window")
else
@bitmap = bitmap
count_wh
update
end
end
#--------------------------------------------------------------------------
# ● 图形
#--------------------------------------------------------------------------
def bitmap
return @bitmap
end
#--------------------------------------------------------------------------
# ● X 坐标(x)
#--------------------------------------------------------------------------
def x=(x)
if @disposed
raise(RGSSError,"disposed window")
else
@x = x
update
end
end
def x
return @x
end
#--------------------------------------------------------------------------
# ● Y 坐标(y)
#--------------------------------------------------------------------------
def y=(y)
if @disposed
raise(RGSSError,"disposed window")
else
@y = y
update
end
end
def y
return @y
end
#--------------------------------------------------------------------------
# ● Z 坐标(z)
#--------------------------------------------------------------------------
def z=(z)
if @disposed
raise(RGSSError,"disposed window")
else
@z = z
update
end
end
def z
return @z
end
#--------------------------------------------------------------------------
# ● X 漂移量(ox)
#--------------------------------------------------------------------------
def ox=(ox)
if @disposed
raise(RGSSError,"disposed window")
else
if @bitmap
@ox = ox
@ox2 = ox % (@bitmap.width * @zoom_x).to_i
update
end
end
end
def ox
return @ox
end
#--------------------------------------------------------------------------
# ● Y 漂移量(oy)
#--------------------------------------------------------------------------
def oy=(oy)
if @disposed
raise(RGSSError,"disposed window")
else
if @bitmap
@oy = oy
@oy2 = oy % (@bitmap.height * @zoom_y).to_i
update
end
end
end
def oy
return @oy
end
#--------------------------------------------------------------------------
# ● X 方向缩放(zoom_x)
#--------------------------------------------------------------------------
def zoom_x=(zx)
if @disposed
raise(RGSSError,"disposed window")
else
if @zoom_x != zx
@zoom_x = zx
count_wh
end
update
end
end
def zoom_x
return @zoom_x
end
#--------------------------------------------------------------------------
# ● Y 方向缩放(zoom_y)
#--------------------------------------------------------------------------
def zoom_y=(zy)
if @disposed
raise(RGSSError,"disposed window")
else
if @zoom_y != zy
@zoom_y = zy
count_wh
end
update
end
end
def zoom_y
return @zoom_y
end
#--------------------------------------------------------------------------
# ● 不透明度(opacity)
#--------------------------------------------------------------------------
def opacity=(op)
if @disposed
raise(RGSSError,"disposed window")
else
@opacity = op
update
end
end
def opacity
return @opacity
end
#--------------------------------------------------------------------------
# ● 颜色叠加(color)
#--------------------------------------------------------------------------
def color=(c)
if @disposed
raise(RGSSError,"disposed window")
else
@color = c
update
end
end
def color
return @color
end
#--------------------------------------------------------------------------
# ● 色调(tone)
#--------------------------------------------------------------------------
def tone=(tone)
if @disposed
raise(RGSSError,"disposed window")
else
@tone = tone
update
end
end
def tone
return @tone
end
#--------------------------------------------------------------------------
# ● 是否可见(visible)
#--------------------------------------------------------------------------
def visible=(v)
if @disposed
raise(RGSSError,"disposed window")
else
@visible = v
update
end
end
def visible
return @visible
end
#--------------------------------------------------------------------------
# ● 叠加模式(blend_type)
#--------------------------------------------------------------------------
def blend_type=(bt)
if @disposed
raise(RGSSError,"disposed window")
else
@blend_type = bt
update
end
end
def blend_type
return @blend_type
end
#--------------------------------------------------------------------------
# ● 释放内存(dispose)
#--------------------------------------------------------------------------
def dispose
return if @disposed
@disposed = true
@contents.bitmap.dispose if @contents.bitmap && !@contents.bitmap.disposed?
@contents.bitmap = nil
@contents.dispose if @contents && !@contents.disposed?
@contents = nil
@bitmap.dispose if @bitmap && !@bitmap.disposed?
@bitmap = nil
end
#--------------------------------------------------------------------------
# ● 检测释放(disposed?)
#--------------------------------------------------------------------------
def disposed?
@disposed
end
#--------------------------------------------------------------------------
# ● 计算Plane的长宽与精灵排布(count_wh)
#--------------------------------------------------------------------------
def count_wh
if @bitmap
@n_w = @rect.width / (@bitmap.width * @zoom_x).to_i + 2
@n_h = @rect.height / (@bitmap.height * @zoom_y).to_i + 2
h = @n_h * (@bitmap.height * @zoom_y).to_i
w = @n_w * (@bitmap.width * @zoom_x).to_i
@contents.bitmap.dispose if @contents.bitmap && !@contents.bitmap.disposed?
@contents.bitmap = Bitmap.new(w, h)
for x in 0..@n_w
for y in 0..@n_h
rect = Rect.new(0,0,@bitmap.width,@bitmap.height)
dest_rect = Rect.new(x * @bitmap.width * @zoom_x,
y * @bitmap.height * @zoom_y,@bitmap.width * @zoom_x,
@bitmap.height * @zoom_y)
@contents.bitmap.stretch_blt(dest_rect, @bitmap, rect)
end
end
end
end
end