粗略的做了个大概,用在事件中或脚本栏中都可以
$sprite_choice = {}
$sprite_choice["选项1"]=["图片1",0,0,:a]
$sprite_choice["选项2"]=["图片2",100,0,:b]
SceneManager.call(Scene_SpriteChoice)
第一行和最后一行不要动,中间的自己添加
上面的例子中,"选项1"是在画面中描绘出来让你看到的选项的名称
"图片1"是选项图片的文件名
后面的两个数字分别是x,y坐标
最后的:a和:b是选择了该选项后执行的函数名,这个得你自己设定,你需要在点击后怎么做,就在脚本里怎么写,如果你不在脚本里写对应的方法,那默认是会p一个index出来,这里也是可以随便改的
如果你需要的选项基本上都在执行同一件事,那就直接在p @index这行写,如果你需要哪个选项做完全不同的事情,那就直接在类里定义一个就行了
class Scene_SpriteChoice < Scene_MenuBase def start super @index = 0 @sprite_choice = [] @sprite_method = [] create_sprites create_method end def create_method @sprite_method.each do |m| eval <<-end_eval def #{m} p @index end end_eval end end def create_background @background_sprite = Sprite.new @background_sprite.bitmap = SceneManager.background_bitmap end def create_sprites $sprite_choice.each_value do |i| sprite = Sprite.new sprite.bitmap = Cache.picture(i[0]) sprite.x = i[1] sprite.y = i[2] @sprite_choice << sprite @sprite_method << i[3] sprite.bitmap.draw_text(i[1],i[2]+100,200,24,$sprite_choice.index([i[0],i[1],i[2],i[3]])) end end def update super update_sprite_choice input_sprite update_choice end def update_sprite_choice @sprite_choice.each {|i|i.update} end def input_sprite return unless Input.dir4 > 0 case Input.dir4 when 2,6 @index += 1 when 4,8 @index -= 1 end @index = 0 if @index > @sprite_choice.size - 1 @index = @sprite_choice.size - 1 if @index < 0 @sprite_choice.each {|i|i.zoom_x,i.zoom_y=1,1} @sprite_choice[@index].zoom_x = 1.2 @sprite_choice[@index].zoom_y = 1.2 end def update_choice if Input.trigger?(:C) method(@sprite_method[@index]).call end return_scene if Input.trigger?(:B) end def dispose super dispose_sprite_choice end def dispose_sprite_choice @sprite_choice.each {|i|i.dispose} end end
class Scene_SpriteChoice < Scene_MenuBase
def start
super
@index = 0
@sprite_choice = []
@sprite_method = []
create_sprites
create_method
end
def create_method
@sprite_method.each do |m|
eval <<-end_eval
def #{m}
p @index
end
end_eval
end
end
def create_background
@background_sprite = Sprite.new
@background_sprite.bitmap = SceneManager.background_bitmap
end
def create_sprites
$sprite_choice.each_value do |i|
sprite = Sprite.new
sprite.bitmap = Cache.picture(i[0])
sprite.x = i[1]
sprite.y = i[2]
@sprite_choice << sprite
@sprite_method << i[3]
sprite.bitmap.draw_text(i[1],i[2]+100,200,24,$sprite_choice.index([i[0],i[1],i[2],i[3]]))
end
end
def update
super
update_sprite_choice
input_sprite
update_choice
end
def update_sprite_choice
@sprite_choice.each {|i|i.update}
end
def input_sprite
return unless Input.dir4 > 0
case Input.dir4
when 2,6
@index += 1
when 4,8
@index -= 1
end
@index = 0 if @index > @sprite_choice.size - 1
@index = @sprite_choice.size - 1 if @index < 0
@sprite_choice.each {|i|i.zoom_x,i.zoom_y=1,1}
@sprite_choice[@index].zoom_x = 1.2
@sprite_choice[@index].zoom_y = 1.2
end
def update_choice
if Input.trigger?(:C)
method(@sprite_method[@index]).call
end
return_scene if Input.trigger?(:B)
end
def dispose
super
dispose_sprite_choice
end
def dispose_sprite_choice
@sprite_choice.each {|i|i.dispose}
end
end
|