Project1
标题: 请问,如何做到刷新很多图片。但又不会让程序自动关闭? [打印本页]
作者: ad1234a 时间: 2011-7-6 19:06
标题: 请问,如何做到刷新很多图片。但又不会让程序自动关闭?
每次内存占用一到430多M就自动关闭的。我感觉这个问题是因为图片刷新太多引起的:
标题画面(有同样问题的是主菜单)的脚本(要考虑到鼠标支持的):- #==============================================================================
- # ■ Scene_Title
- #------------------------------------------------------------------------------
- # 处理标题画面的类。
- #==============================================================================
- class Scene_Title
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # menu_index : 命令光标的初期位置
- #--------------------------------------------------------------------------
- def initialize(title_index = 0)
- @title_index = title_index
- end
- #--------------------------------------------------------------------------
- # ● 住处理
- #--------------------------------------------------------------------------
- def main
- # 战斗测试的情况下
- if $BTEST
- battle_test
- return
- end
- # 载入数据库
- # file = File.open("Data/lang.rxdata", "rb")
- # $game_System_variables = Marshal.load(file)
- # file.close
-
- $data_actors = load_data("Data/Actors.rxdata")
- $data_classes = load_data("Data/Classes.rxdata")
- $data_skills = load_data("Data/Skills.rxdata")
- $data_items = load_data("Data/Items.rxdata")
- $data_weapons = load_data("Data/Weapons.rxdata")
- $data_armors = load_data("Data/Armors.rxdata")
- $data_enemies = load_data("Data/Enemies.rxdata")
- $data_troops = load_data("Data/Troops.rxdata")
- $data_states = load_data("Data/States.rxdata")
- $data_animations = load_data("Data/Animations.rxdata")
- $data_tilesets = load_data("Data/Tilesets.rxdata")
- $data_common_events = load_data("Data/CommonEvents.rxdata")
- $data_system = load_data("Data/System.rxdata")
- $game_System_variables = load_data("Data/lang.rxdata")
-
- # 生成系统对像
- $game_system = Game_System.new
- # 生成标题图形
- @sprite = Sprite.new
- @sprite.bitmap = RPG::Cache.title($data_system.title_name)
- # @command = Sprite.new
- # @command.bitmap = Bitmap.new("Graphics/Pictures/titles/title_1")
- #@command.x = 370
- #@command.y = 230
-
- @Title_command_1 = Sprite.new
- @Title_command_1.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-2")
- @Title_command_1.x = 510
- @Title_command_1.y = 270
-
- @Title_command_2 = Sprite.new
- @Title_command_2.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-3")
- @Title_command_2.x = 510
- @Title_command_2.y = 320
-
- @Title_command_3 = Sprite.new
- @Title_command_3.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-4")
- @Title_command_3.x = 510
- @Title_command_3.y = 370
-
- @Title_command_4 = Sprite.new
- @Title_command_4.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-5")
- @Title_command_4.x = 510
- @Title_command_4.y = 420
-
- @Title_command_5 = Sprite.new
- @Title_command_5.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-6")
- @Title_command_5.x = 510
- @Title_command_5.y = 470
-
- @system_variable_value = 1
-
- # 生成命令窗口
-
- # s1 = "故事模式"
- #s2 = "遊戲設定"
- # s3 = "附加內容"
- # s4 = "退出遊戲"
-
- s1 = ""
- s2 = ""
- s3 = ""
- s4 = ""
- s5 = ""
-
- settings1 = "繁體中文"
- settings2 = "简体中文"
-
- # if @system_variable_value == 1
- # @command.bitmap = Bitmap.new("Graphics/Pictures/titles/title_1")
- # end
-
-
- @Title_system_window = Window_Command_Title.new(122, [settings1, settings2])
- @Title_system_window.back_opacity = 160
- @Title_system_window.opacity = 0
- @Title_system_window.x = 500 - @Title_system_window.width / 2
- @Title_system_window.y = 258
- @Title_system_window.visible = false
- @Title_system_window.active = false
-
- @command_window = Window_Command_Title.new(192, [s1, s2, s3 ,s4 , s5])
- @command_window.back_opacity = 160
- @command_window.opacity = 0
- @command_window.x = 620 - @command_window.width / 2
- @command_window.y = 258
- @command_window.windowskin = RPG::Cache.windowskin("")
- @command_window.index = @title_index
- # 演奏标题 BGM
- $game_system.bgm_play($data_system.title_bgm)
-
- # 停止演奏 ME、BGS
- Audio.me_stop
- Audio.bgs_stop
- # 执行过渡
- Graphics.transition
- # 主循环
- loop do
- # 刷新游戏画面
- Graphics.update
- # 刷新输入信息
- Input.update
- # 刷新画面
- update
- # 如果画面被切换就中断循环
- if $scene != self
- break
- end
- end
- # 装备过渡
- Graphics.freeze
- # 释放命令窗口
- @command_window.dispose
- # 释放标题图形
- @sprite.bitmap.dispose
- @sprite.dispose
- #@command.dispose
- @Title_command_1.dispose
- @Title_command_2.dispose
- @Title_command_3.dispose
- @Title_command_4.dispose
- @Title_command_5.dispose
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- # 刷新命令窗口
- @command_window.update
- if @Title_system_window.active
- @Title_system_window.update
- end
-
- case @command_window.index
- when 0 # 開始遊戲
- @wait_count = 20
- @Title_command_1.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-7")
- @Title_command_2.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-3")
- @Title_command_3.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-4")
- @Title_command_4.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-5")
- @Title_command_5.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-6")
- #@command.bitmap = Bitmap.new("Graphics/Pictures/titles/title_1")
- when 1 # 讀取遊戲
- @wait_count = 20
- # @command.bitmap = Bitmap.new("Graphics/Pictures/titles/title_2")
- @Title_command_1.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-2")
- @Title_command_2.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-8")
- @Title_command_3.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-4")
- @Title_command_4.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-5")
- @Title_command_5.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-6")
- when 2 # 遊戲設定
- @wait_count = 20
- # @command.bitmap = Bitmap.new("Graphics/Pictures/titles/title_3")
- @Title_command_1.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-2")
- @Title_command_2.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-3")
- @Title_command_3.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-9")
- @Title_command_4.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-5")
- @Title_command_5.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-6")
- when 3 # 離開遊戲
- @wait_count = 20
- @Title_command_1.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-2")
- @Title_command_2.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-3")
- @Title_command_3.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-4")
- @Title_command_4.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-10")
- @Title_command_5.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-6")
- when 4 #
- @wait_count = 20
- @Title_command_1.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-2")
- @Title_command_2.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-3")
- @Title_command_3.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-4")
- @Title_command_4.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-5")
- @Title_command_5.bitmap = Bitmap.new("Graphics/Pictures/title_command/63-11")
-
- end
-
-
- if @Title_system_window.active
- if Input.trigger?(Input::B)
- @command_window.active = true
- @command_window.visible = true
- @Title_system_window.active = false
- @Title_system_window.visible = false
- end
- end
-
- # 按下 C 键的情况下
- if Input.trigger?(Input::C)
- case @Title_system_window.index
- when 0
- system_cht
- when 1
- system_chs
- end
-
- # 命令窗口的光标位置的分支
- case @command_window.index
- when 0 # 新游戏
- command_new_game
- when 1 # 继续
- command_continue
- when 2 # 系统设定
- command_systemsettings
- when 3 # 退出
- command_shutdown
- when 4 #
- command_movie
- end
- end
- end
-
- #-----------------------------------
-
-
- #--------------------------------------------------------------------------
- # ● 命令 : 新游戏
- #--------------------------------------------------------------------------
- def command_new_game
- # 演奏确定 SE
- $game_system.se_play($data_system.decision_se)
- # 停止 BGM
- Audio.bgm_stop
- # 重置测量游戏时间用的画面计数器
- Graphics.frame_count = 0
- # 生成各种游戏对像
- $game_temp = Game_Temp.new
- $game_system = Game_System.new
- $game_switches = Game_Switches.new
- $game_variables = Game_Variables.new
- $game_self_switches = Game_SelfSwitches.new
- $game_screen = Game_Screen.new
- $game_actors = Game_Actors.new
- $game_party = Game_Party.new
- $game_troop = Game_Troop.new
- $game_map = Game_Map.new
- $game_player = Game_Player.new
- #$game_System_variables = load_data("Data/lang.rxdata")
-
- # 设置初期同伴位置
- $game_party.setup_starting_members
- # 设置初期位置的地图
- $game_map.setup($data_system.start_map_id)
- # 主角向初期位置移动
- $game_player.moveto($data_system.start_x, $data_system.start_y)
- # 刷新主角
- $game_player.refresh
- # 执行地图设置的 BGM 与 BGS 的自动切换
- $game_map.autoplay
- # 刷新地图 (执行并行事件)
- $game_map.update
- # 切换地图画面
- $scene = Scene_Map.new
- end
- #--------------------------------------------------------------------------
- # ● 命令 : 继续
- #--------------------------------------------------------------------------
- def command_continue
- # 继续无效的情况下
- # unless @continue_enabled
- # 演奏无效 SE
- # $game_system.se_play($data_system.buzzer_se)
- # return
- # end
- # 演奏确定 SE
- $game_system.se_play($data_system.decision_se)
- # 切换到读档画面
- $scene = Scene_Load.new
- end
- #--------------------------------------------------------------------------
- # ● 命令 : 退出
- #--------------------------------------------------------------------------
- def command_shutdown
- # 演奏确定 SE
- $game_system.se_play($data_system.decision_se)
- # BGM、BGS、ME 的淡入淡出
- Audio.bgm_fade(800)
- Audio.bgs_fade(800)
- Audio.me_fade(800)
- # 退出
- $scene = nil
- end
- #--------------------------------------------------------------------------
- # ● 命令 : 系統設定
- #--------------------------------------------------------------------------
- def command_systemsettings
- # 演奏确定 SE
- $game_system.se_play($data_system.decision_se)
- #$scene = Scene_SystemSettings.new
- @Title_system_window.active = true
- @Title_system_window.visible = true
- @command_window.active = false
- @command_window.visible = false
- end
-
- #--------------------------------------------------------------------------
- # ● 命令 : 過場動畫
- #--------------------------------------------------------------------------
- def command_movie
- # 继续无效的情况下
- # unless @continue_enabled
- # 演奏无效 SE
- $game_system.se_play($data_system.buzzer_se)
- # return
- end
-
- #--------------------------------------------------------------------------
- # 以下为與語言設定有關部分,請別亂改動
- #--------------------------------------------------------------------------
-
- def system_cht
- $game_system.se_play($data_system.decision_se)
- #此為繁體版程式所用
- # @system_variable_value = 1
- #$data_system = load_data("Data/System_1.rxdata")
- # file=File.open("Data/lang.rxdata", "wb")
- # Marshal.dump($game_System_variables, file)
- # file.close
-
- @command_window.active = true
- @command_window.visible = true
- @Title_system_window.active = false
- @Title_system_window.visible = false
- end
-
- def system_chs
- $game_system.se_play($data_system.decision_se)
-
- #此为簡體版程式所用
- # @system_variable_value = 2
- #$data_system = load_data("Data/System_1.rxdata")
- # file=File.open("Data/lang.rxdata", "wb")
- # Marshal.dump($game_System_variables, file)
- # file.close
-
- @command_window.active = true
- @command_window.visible = true
- @Title_system_window.active = false
- @Title_system_window.visible = false
- end
-
- #--------------------------------------------------------------------------
- # ● 战斗测试
- #--------------------------------------------------------------------------
- def battle_test
- # 载入数据库 (战斗测试用)
- $data_actors = load_data("Data/Actors.rxdata")
- $data_classes = load_data("Data/Classes.rxdata")
- $data_skills = load_data("Data/Skills.rxdata")
- $data_items = load_data("Data/Items.rxdata")
- $data_weapons = load_data("Data/Weapons.rxdata")
- $data_armors = load_data("Data/Armors.rxdata")
- $data_enemies = load_data("Data/Enemies.rxdata")
- $data_troops = load_data("Data/Troops.rxdata")
- $data_states = load_data("Data/States.rxdata")
- $data_animations = load_data("Data/Animations.rxdata")
- $data_tilesets = load_data("Data/Tilesets.rxdata")
- $data_common_events = load_data("Data/CommonEvents.rxdata")
- $data_system = load_data("Data/System.rxdata")
- # 重置测量游戏时间用的画面计数器
- Graphics.frame_count = 0
- # 生成各种游戏对像
- $game_temp = Game_Temp.new
- $game_system = Game_System.new
- $game_switches = Game_Switches.new
- $game_variables = Game_Variables.new
- $game_self_switches = Game_SelfSwitches.new
- $game_screen = Game_Screen.new
- $game_actors = Game_Actors.new
- $game_party = Game_Party.new
- $game_troop = Game_Troop.new
- $game_map = Game_Map.new
- $game_player = Game_Player.new
- # 设置战斗测试用同伴
- $game_party.setup_battle_test_members
- # 设置队伍 ID、可以逃走标志、战斗背景
- $game_temp.battle_troop_id = $data_system.test_troop_id
- $game_temp.battle_can_escape = true
- $game_map.battleback_name = $data_system.battleback_name
- # 演奏战斗开始 BGM
- $game_system.se_play($data_system.battle_start_se)
- # 演奏战斗 BGM
- $game_system.bgm_play($game_system.battle_bgm)
- # 切换到战斗画面
- $scene = Scene_Battle.new
- end
- end
复制代码 另外,这个是主菜单的刷新部分:- if @menu_window.active
- case @menu_window.index
- when 0
- @command2_1.bitmap = Bitmap.new("Graphics/Pictures/物品·一")
- @command2_2.bitmap = Bitmap.new("Graphics/Pictures/装备·平常")
- @command2_3.bitmap = Bitmap.new("Graphics/Pictures/奇术·一")
- @command2_4.bitmap = Bitmap.new("Graphics/Pictures/天书·平常")
- @command2_5.bitmap = Bitmap.new("Graphics/Pictures/记载·平常")
- @command2_6.bitmap = Bitmap.new("Graphics/Pictures/系统·平常")
- when 1
- @command2_1.bitmap = Bitmap.new("Graphics/Pictures/物品·平常")
- @command2_2.bitmap = Bitmap.new("Graphics/Pictures/装备·一")
- @command2_3.bitmap = Bitmap.new("Graphics/Pictures/奇术·一")
- @command2_4.bitmap = Bitmap.new("Graphics/Pictures/天书·平常")
- @command2_5.bitmap = Bitmap.new("Graphics/Pictures/记载·平常")
- @command2_6.bitmap = Bitmap.new("Graphics/Pictures/系统·平常")
- when 2
- @command2_1.bitmap = Bitmap.new("Graphics/Pictures/物品·平常")
- @command2_2.bitmap = Bitmap.new("Graphics/Pictures/装备·平常")
- @command2_3.bitmap = Bitmap.new("Graphics/Pictures/奇术·二")
- @command2_4.bitmap = Bitmap.new("Graphics/Pictures/天书·平常")
- @command2_5.bitmap = Bitmap.new("Graphics/Pictures/记载·平常")
- @command2_6.bitmap = Bitmap.new("Graphics/Pictures/系统·平常")
- when 3
- @command2_1.bitmap = Bitmap.new("Graphics/Pictures/物品·平常")
- @command2_2.bitmap = Bitmap.new("Graphics/Pictures/装备·平常")
- @command2_3.bitmap = Bitmap.new("Graphics/Pictures/奇术·一")
- @command2_4.bitmap = Bitmap.new("Graphics/Pictures/天书·一")
- @command2_5.bitmap = Bitmap.new("Graphics/Pictures/记载·平常")
- @command2_6.bitmap = Bitmap.new("Graphics/Pictures/系统·平常")
- when 4
- @command2_1.bitmap = Bitmap.new("Graphics/Pictures/物品·平常")
- @command2_2.bitmap = Bitmap.new("Graphics/Pictures/装备·平常")
- @command2_3.bitmap = Bitmap.new("Graphics/Pictures/奇术·一")
- @command2_4.bitmap = Bitmap.new("Graphics/Pictures/天书·平常")
- @command2_5.bitmap = Bitmap.new("Graphics/Pictures/记载·一")
- @command2_6.bitmap = Bitmap.new("Graphics/Pictures/系统·平常")
- when 5
- @command2_1.bitmap = Bitmap.new("Graphics/Pictures/物品·平常")
- @command2_2.bitmap = Bitmap.new("Graphics/Pictures/装备·平常")
- @command2_3.bitmap = Bitmap.new("Graphics/Pictures/奇术·一")
- @command2_4.bitmap = Bitmap.new("Graphics/Pictures/天书·平常")
- @command2_5.bitmap = Bitmap.new("Graphics/Pictures/记载·平常")
- @command2_6.bitmap = Bitmap.new("Graphics/Pictures/系统·一")
- end
- end
复制代码