class Sprite_Plane < Sprite
def initialize(viewport)
super(viewport)
self.z=viewport.z
@plane_bmp=nil # original plane bmp, for self.bitmap stores tiled bitmap
@contents = Bitmap.new(viewport.rect.width, viewport.rect.height)
self.bitmap=nil
end
# 外部使用。内部没有用到所以不需要alias
def bitmap
return @plane_bmp
end
alias bmp_set bitmap= # 内部使用,真实修改bitmap
def bitmap=(bmp) # 外部使用,先赋值给@plane_bmp再刷新
@plane_bmp = bmp
refresh
end
def dispose
@contents.dispose
end
# 坐标的处理
alias ox_set ox=
def ox=(x)
self.ox_set(x % @plane_bmp.width) rescue self.ox_set(x)
end
alias oy_set oy=
def oy=(y)
self.oy_set(y % @plane_bmp.height) rescue self.oy_set(y)
end
def refresh
@contents.clear
return if @plane_bmp == nil
cw=(@plane_bmp.width*self.zoom_x).to_i
ch=(@plane_bmp.height*self.zoom_y).to_i
@n_w = @contents.width / cw + 3
@n_h = @contents.height / ch + 3
# 预处理缩放后的图片
tmp = Bitmap.new(cw, ch)
tmp.stretch_blt(tmp.rect, @plane_bmp, @plane_bmp.rect)
# 平铺
for x in 0..@n_w
for y in 0..@n_h
@contents.blt(x * cw, y * ch, tmp, tmp.rect)
end
end
# 将处理好的图形传给bitmap
self.bmp_set(@contents)
tmp.dispose
end
end
class Sprite_Plane < Sprite
def initialize(viewport)
super(viewport)
self.z=viewport.z
@plane_bmp=nil # original plane bmp, for self.bitmap stores tiled bitmap
@contents = Bitmap.new(viewport.rect.width, viewport.rect.height)
self.bitmap=nil
end
# 外部使用。内部没有用到所以不需要alias
def bitmap
return @plane_bmp
end
alias bmp_set bitmap= # 内部使用,真实修改bitmap
def bitmap=(bmp) # 外部使用,先赋值给@plane_bmp再刷新
@plane_bmp = bmp
refresh
end
def dispose
@contents.dispose
end
# 坐标的处理
alias ox_set ox=
def ox=(x)
self.ox_set(x % @plane_bmp.width) rescue self.ox_set(x)
end
alias oy_set oy=
def oy=(y)
self.oy_set(y % @plane_bmp.height) rescue self.oy_set(y)
end
def refresh
@contents.clear
return if @plane_bmp == nil
cw=(@plane_bmp.width*self.zoom_x).to_i
ch=(@plane_bmp.height*self.zoom_y).to_i
@n_w = @contents.width / cw + 3
@n_h = @contents.height / ch + 3
# 预处理缩放后的图片
tmp = Bitmap.new(cw, ch)
tmp.stretch_blt(tmp.rect, @plane_bmp, @plane_bmp.rect)
# 平铺
for x in 0..@n_w
for y in 0..@n_h
@contents.blt(x * cw, y * ch, tmp, tmp.rect)
end
end
# 将处理好的图形传给bitmap
self.bmp_set(@contents)
tmp.dispose
end
end