本帖最后由 iisnow 于 2012-3-24 16:07 编辑
你都有这个Firefly类的话,这需要在Scene里把它们实例化就可以了啊
但是一个Firefly只有一个点,所以就多实例化几个,最好用数组管理;
然后只需要考虑3步就可以了:实例化new,更新update,释放dispose
用数组一起管理即可,可能还要调整下显示的层次
class Scene_Title MAX_FLY = 90 # Firfly的数目(图大的话,数字就要小,不然卡) alias :iisnow_start :start def start iisnow_start create_firefly @command_window.z = 102 # 使得窗口在光点上面 end def create_firefly @fly_sprite = [] MAX_FLY.times{@fly_sprite << Firefly.new} @fly_sprite.each{|s| s.z = 101} # 比上的设置值小,比100大即可 end def update super @fly_sprite.each{|s| s.update } end alias :iisnow_terminate :terminate def terminate iisnow_terminate dispose_firefly end def dispose_firefly @fly_sprite.each{|s| s.dispose} end end class Firefly < Sprite def initialize(viewport = nil) super(viewport) self.bitmap = Cache.title2("Firefly") reset_setting end def reset_setting zoom = (50 + rand(100)) / 100.1 self.zoom_x = zoom self.zoom_y = zoom self.x = rand(544) self.y = rand(416 + self.bitmap.height) self.opacity = 0 self.angle = rand(360) self.blend_type = 1 @speed_x = 0 @speed_y = [[rand(4), 4].min, 1].max @speed_a = rand(3) end def dispose super self.bitmap.dispose end def update super self.x += @speed_x self.y -= @speed_y self.angle += @speed_a self.opacity += 5 reset_setting if self.y < 0 end end
class Scene_Title
MAX_FLY = 90 # Firfly的数目(图大的话,数字就要小,不然卡)
alias :iisnow_start :start
def start
iisnow_start
create_firefly
@command_window.z = 102 # 使得窗口在光点上面
end
def create_firefly
@fly_sprite = []
MAX_FLY.times{@fly_sprite << Firefly.new}
@fly_sprite.each{|s| s.z = 101} # 比上的设置值小,比100大即可
end
def update
super
@fly_sprite.each{|s| s.update }
end
alias :iisnow_terminate :terminate
def terminate
iisnow_terminate
dispose_firefly
end
def dispose_firefly
@fly_sprite.each{|s| s.dispose}
end
end
class Firefly < Sprite
def initialize(viewport = nil)
super(viewport)
self.bitmap = Cache.title2("Firefly")
reset_setting
end
def reset_setting
zoom = (50 + rand(100)) / 100.1
self.zoom_x = zoom
self.zoom_y = zoom
self.x = rand(544)
self.y = rand(416 + self.bitmap.height)
self.opacity = 0
self.angle = rand(360)
self.blend_type = 1
@speed_x = 0
@speed_y = [[rand(4), 4].min, 1].max
@speed_a = rand(3)
end
def dispose
super
self.bitmap.dispose
end
def update
super
self.x += @speed_x
self.y -= @speed_y
self.angle += @speed_a
self.opacity += 5
reset_setting if self.y < 0
end
end
|