VX Ace - question on disposing bitmaps

Discussion in 'RGSSx Script Support' started by boyflea, Mar 17, 2017.

  1. boyflea

    boyflea boyflea Veteran

    Messages:
    51
    Likes Received:
    14
    Location:
    Southampton, England
    First Language:
    English
    Primarily Uses:
    RMVXA
    Hi, apologies if thsi is in the wrong place, but thought I'd make a fool of myself:

    I have been scouring the VX Ace scripts, putting things together:
    on this thread:
    https://forums.rpgmakerweb.com/inde...d-gameover-v2-4-unofficial.15139/#post-712872

    I have been trying to add two scripts to teh homepage screen taht allows for intro and credits from menu options.
    Now they may be clashing or maybe I have just set things up wrong - however, my question is probably best addressed as a wider issue: I suspect I am failing to setup my classes incorrectly.

    When I run this cut n pasted code, it has issues disposing of the backgroudn bitmaps when dismissing the credits section.

    Having reviewed the counterparrts in the super classes and in the other mods, they all state soemthing like this:

    def dispose_background1
    @sprite1.bitmap.dispose
    @sprite1.bitmap = nil
    @sprite1.dispose
    @sprite1 = nil
    end

    now, for the credits section, for some reason I get this error:

    Script 'MOG&DP - Gameover' line 180:NoMethodError occured.
    Undefined method 'bitmap' for nil:NilClass



    so why would something that works for one set of classes fail for this one?

    I include the THREE seperate entries I have relating to my homescreen setup, with the third one managing the CREDITS screen.


    my three scripts for homepage are here: SCRIPT 3 has the issue. SCRIPT 1 and 2 seem fine, but I do wonder if they have a role in this.

    VX ACE:
    #1 MY ATTEMPT TO SETUP COMMAND MENU
    #===============================================================================
    # Pearl ABS display tittle, this is not needed to run the system

    #===========new title
    # retnuh help
    # Soulpour777 credits
    ### Shiggy's menu options: (C) 2016

    #--------------------------------------------------------------------------
    # UPDATED COMMAND MENU
    #--------------------------------------------------------------------------
    class Window_TitleCommand < Window_Command
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize
    super(0, 0)
    update_placement
    select_symbol:)new_game) if !continue_enabled # Replace the default line with this
    self.openness = 0
    open
    end

    alias retnuh_title_make_command_list make_command_list
    def make_command_list
    retnuh_title_make_command_list
    add_command(Vocab::new_game, :new_game)
    add_command(Vocab::continue, :continue, continue_enabled)
    add_command("Tutorial", :tutorial)
    add_command("Oracle", :oracle)
    add_command("Credits",:credits)
    add_command(Vocab::shutdown, :shutdown)
    end

    end

    #=======================================================================
    #### scene title update
    #=======================================================================

    class Scene_Title < Scene_Base

    alias retnuh_title_create_command_window create_command_window
    def create_command_window
    retnuh_title_create_command_window
    #first argument is the key you used previously,second one is the name of the method that will be executed
    @command_window.set_handler:)new_game, method:)command_new_game))
    @command_window.set_handler:)continue, method:)command_continue))
    @command_window.set_handler:)tutorial, method:)command_tutorial))
    @command_window.set_handler:)oracle, method:)command_oracle))
    @command_window.set_handler:)credits, method:)command_credits))
    @command_window.set_handler:)shutdown, method:)command_shutdown))

    #add as many as you had previously
    end

    #--------------------------------------------------------------------------
    # * [TUTORIAL] Command
    #--------------------------------------------------------------------------

    #create a new_method with the name you used before
    def command_tutorial
    #this is the standard command_new_game_block
    DataManager.setup_new_game
    close_command_window
    fadeout_all
    $game_map.autoplay
    #I add two line just before the line that open the map screen

    ##SETUP DESTINATION OF WHERE WE START ON NEW MAP...
    $game_map.setup(12) #arg is the map_id of the map where you wanna be
    $game_player.moveto(26,32) # args are the x,y positions on the map

    SceneManager.goto(Scene_Map)
    end

    #--------------------------------------------------------------------------
    # * [ORACLE] Command
    #--------------------------------------------------------------------------

    #create a new_method with the name you used before
    def command_oracle
    #this is the standard command_new_game_block
    DataManager.setup_new_game
    close_command_window
    fadeout_all
    $game_map.autoplay
    #I add two line just before the line that open the map screen
    ##SETUP DESTINATION OF WHERE WE START ON NEW MAP...
    $game_map.setup(13) #arg is the map_id of the map where you wanna be
    $game_player.moveto(10,66) # args are the x,y positions on the map

    SceneManager.goto(Scene_Map)
    end

    #--------------------------------------------------------------------------
    # * [CREDITS] Command
    #--------------------------------------------------------------------------

    def command_credits
    #DataManager.setup_new_game
    close_command_window
    fadeout_all
    SceneManager.goto(Scene_Gameover)
    end


    #/
    end

    #2 INTRO SCRIPT
    #==============================================================================
    # +++ MOG - Animated Title A (v2.4) +++
    #==============================================================================
    # By Moghunter
    # http://www.atelier-rgss.com/
    #==============================================================================
    # Tela de titulo animado, com logo, imagens aleatórias e outros efeitos visuais.
    #==============================================================================

    #==============================================================================
    # IMAGENS NECESSÁRIAS
    #==============================================================================
    # Serão necessários as seguintes imagens na pasta Graphics/Titles2/
    #
    # Cursor.png
    # Commmand_Name.png (image filename = name of command)
    # Particle.png (Opcional)
    # Logo.jpg (Opcional)
    # Animated.png (Opcional)
    #==============================================================================

    #==============================================================================
    # NOTA 1 - Para definir a imagem de texto basta selecionar no banco de dados
    # a imagem do titulo numero 2 (Segunda camada)
    #==============================================================================

    #==============================================================================
    # NOTA 2 - O nome da imagem de comando é iguál ao nome do comando definido
    # no banco de dados do Rpg Maker.
    #==============================================================================


    #==============================================================================
    # ● Histórico (Version History)
    #==============================================================================
    # v 2.4 - Compatibilidade com resoluções acima do padrão.
    # v 2.3 - O nome do comando não é mais baseado no database.
    #==============================================================================

    module MOG_SCENE_TITLE_A

    #--------------------------------------------------------------------------
    # ▼ MODULE: MG_SCENE_TITLE_A > LOGO ▼
    #--------------------------------------------------------------------------
    # Apresenta um Logo ao começar a tela de titulo.
    # Será necessário ter a imagem LOGO.jpg (png) na pasta Graphics/Title2
    #--------------------------------------------------------------------------
    # Ativar Logo
    LOGO = true
    # Duração do logo.
    LOGO_DURATION = 2 #(Sec)

    #--------------------------------------------------------------------------
    # ▼ MODULE: MG_SCENE_TITLE_A > RANDOM BACKGROUND ▼
    #--------------------------------------------------------------------------
    #Definição das pictures.
    #--------------------------------------------------------------------------
    RANDOM_PICTURES = [
    "Title00", "Title01", "Title02", "Title03","Title04","Title05","Title06","Title07","Title08","Title09","Title10","Title11"
    ]
    #Tempo de duração para ativar a troca de imagens.
    RANDOM_PICTURES_DURATION = 5#(sec)
    #Seleção aleatória.
    RAMDOM_SELECTION = false
    #Velocidade de Scrolling. (Speed X , Speed Y)
    RANDOM_PICTURES_SCROLL_SPEED = [0,0]

    #--------------------------------------------------------------------------
    # ▼ MODULE: MG_SCENE_TITLE_A > MULTIPLE LAYERS ▼
    #--------------------------------------------------------------------------
    # Definição de multiplas camadas. * (não há limíte na quantidade de camadas
    # usadas)
    #--------------------------------------------------------------------------
    # MULTIPLE_LAYERS = [ ["A",B,C,D], ["A",B,C,D], ["A",B,C D], ["A",B,C,D ], ....]
    #
    # A - Nome da imagem.
    # B - Velocidade de scroll na horizontal.
    # C - Velocidade de scroll na vertical.
    # D - Tipo de Blend. (0 - Normal / 2 - Add / 3 - Substract)
    #
    MULTIPLE_LAYERS = [
    ["Layer1",-4,0,0],
    ["Layer2",0,-4,1],
    ["Layer3",1,0,1],
    ["Layer4",2,0,1],
    ["Layer5",0,1,0],
    ["Layer6",0,0,0],
    ]

    #--------------------------------------------------------------------------
    # ▼ MODULE: MG_SCENE_TITLE_A > PARTICLES ▼
    #--------------------------------------------------------------------------
    # Adiciona partículas animadas na tela do titulo.
    # Será necessário ter a imagem PARTICLE.png na pasta Graphics/Title2
    #--------------------------------------------------------------------------
    # Ativar Partículas.
    PARTICLE = false
    # Ativar Cores Aleatórias.
    PARTICLE_RANDOM_COLOR = true
    # Definição do tipo de blend. (0,1,2)
    PARTICLE_BLEND_TYPE = 1
    #Definição do limite de velocidade das partículas.
    PARTICLE_MOVEMENT_RANGE_X = 15
    PARTICLE_MOVEMENT_RANGE_Y = 2
    PARTICLE_ANGLE_RANGE = 2

    #--------------------------------------------------------------------------
    # ▼ MODULE: MG_SCENE_TITLE_A > WAVE TITLE ▼
    #--------------------------------------------------------------------------
    # Ativa o efeito WAVE no texto do titulo, o Texto do titulo é definido
    # na camada do titulo 2, que pode ser definido através do banco de dados
    #--------------------------------------------------------------------------
    #Ativar o efeito do titulo com efeito WAVE.
    TITLE_WAVE = true
    #Configuração do efeito WAVE
    #
    # TITLE_WAVE_CONFIG = [ AMP, LENGTH , SPEED]
    #
    TITLE_WAVE_CONFIG = [6 , 232 , 360]

    #--------------------------------------------------------------------------
    # ▼ MODULE: MG_SCENE_TITLE_A > ANIMATED_SPRITE ▼ (Opcional)
    #--------------------------------------------------------------------------
    # Adiciona um sprite animado no titulo.
    # A quantidade de frames é proporcional a largura dividido pela altura
    # da imagem, ou seja, não há limite de quantidade de frames e nem de
    # tamanho da imagem.
    # Será necessário ter a imagem ANIMATED.png (Jpg) na pasta Graphics/Title2
    #--------------------------------------------------------------------------
    # Ativar Sprite animado.
    ANIMATED_SPRITE = true
    # Posição do Sprite animado.
    ANIMATED_SPRITE_POSITION = [-250,100]
    # Velocidade da animação
    ANIMATED_SPRITE_SPEED = 143
    # Tipo de Blend. (0 - Normal / 2 - Add / 3 - Substract)
    ANIMATED_SPRITE_BLEND_TYPE = 0
    # Definição do zoom,
    ANIMATED_SPRITE_ZOOM = 5


    #--------------------------------------------------------------------------
    # ▼ MODULE: MG_SCENE_TITLE_A > COMMANDS / SELECTION ▼
    #--------------------------------------------------------------------------
    # Configuração extras da tela de titulo.
    #--------------------------------------------------------------------------
    # Posição do comando.
    COMMANDS_POS = [375 , 105]
    # Ativar o efeito de tremor ao selecionar o comando.
    COMMAND_SHAKE = true
    # Definição da posição do cursor.(Para ajustes)
    CURSOR_POS = [0,0]
    # Ativar flash ao mover o comando.
    CURSOR_FLASH_SELECTION = false
    # Definição da posição do flash.
    CURSOR_FLASH_SLECTION_POS = [32,0]
    # Tipo de Blend. (0 - Normal / 2 - Add / 3 - Substract)
    CURSOR_FLASH_SLECTION_BLEND_TYPE = 1

    end

    #==============================================================================
    # ■ CLASS: Window TitleCommand
    #==============================================================================
    class Window_TitleCommand < Window_Command
    attr_reader :list
    end

    #==============================================================================
    # ■ CLASS: Particle Title
    #==============================================================================
    class Particle_Title < Sprite

    include MOG_SCENE_TITLE_A

    #--------------------------------------------------------------------------
    # ● CLASS: Particle Title > Initialize
    #--------------------------------------------------------------------------
    def initialize(viewport = nil)
    super(viewport)
    self.bitmap = Cache.title2("Particle")
    self.tone.set(rand(255),rand(255), rand(255), 255) if PARTICLE_RANDOM_COLOR
    self.blend_type = PARTICLE_BLEND_TYPE
    self.z = 50
    @sc_x = [self.bitmap.width / 2, self.bitmap.width, Graphics.width ]
    @sc_y = [self.bitmap.height / 2, self.bitmap.height, Graphics.height ]

    @cw0 = self.bitmap.width / 2 ; @ch0 = self.bitmap.height / 2
    @cw = self.bitmap.width + @cw0 ; @cw2 = Graphics.width
    @ch = self.bitmap.height + @ch0 ; @ch2 = Graphics.height

    @nx = PARTICLE_MOVEMENT_RANGE_X
    @ny = PARTICLE_MOVEMENT_RANGE_Y
    reset_setting
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Particle Title > Reset Setting
    #--------------------------------------------------------------------------
    def reset_setting
    zoom = (50 + rand(100)) / 100.1
    self.zoom_x = zoom
    self.zoom_y = zoom
    self.x = (rand(@cw2 + 32) -32)
    self.y = rand((@ch2 + 32) + @ch)
    self.opacity = 0
    self.angle = rand(360)
    nx2 = rand(@nx).abs
    nx2 = 1 if (@nx != 0 and nx2 < 1)
    @speed_x = @nx > 0 ? nx2 : @nx < 0 ? -nx2 : 0
    ny2 = rand(@ny).abs
    ny2 = 1 if (@ny != 0 and ny2 < 1)
    @speed_y = @ny > 0 ? ny2 : @ny < 0 ? -ny2 : 0
    @speed_a = [[rand(PARTICLE_ANGLE_RANGE), PARTICLE_ANGLE_RANGE].min, 0].max
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Particle Title > Dispose
    #--------------------------------------------------------------------------
    def dispose
    super
    self.bitmap.dispose
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Particle Title > Update
    #--------------------------------------------------------------------------
    def update
    super
    self.x += @speed_x
    self.y -= @speed_y
    self.angle += @speed_a
    self.opacity += 5
    reset_setting if can_reset_setting?
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Particle Title > Can Reset Setting
    #--------------------------------------------------------------------------
    def can_reset_setting?
    return true if (self.x < -(@cw * 2) or self.x > (@cw2 + @cw))
    return true if (self.y < -(@ch * 2) or self.y > (@ch2 + @ch))
    return false
    end
    end

    #==============================================================================
    # ■ Multiple Layers Title
    #==============================================================================
    class Multiple_Layers_Title

    #--------------------------------------------------------------------------
    # ● CLASS: Multiple Layers Title > Initialize
    #--------------------------------------------------------------------------
    def initialize(name = "", scroll_x = 0, scroll_y = 0, blend = 0, index = 0)
    @layer = Plane.new
    @layer.bitmap = Cache.title1(name.to_s) rescue nil
    @layer.bitmap = Bitmap.new(32,32) if @layer.bitmap == nil
    @layer.z = 10 + index
    @layer.opacity = 0
    @layer.blend_type = blend
    @scroll_speed = [scroll_x, scroll_y]
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Multiple Layers Title > Dispose
    #--------------------------------------------------------------------------
    def dispose
    @layer.bitmap.dispose
    @layer.bitmap = nil
    @layer.dispose
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Multiple Layers Title > Update
    #--------------------------------------------------------------------------
    def update
    @layer.opacity += 2
    @layer.ox += @scroll_speed[0]
    @layer.oy += @scroll_speed[1]
    end

    end

    #==============================================================================
    # ■ Scene Title
    #==============================================================================
    class Scene_Title < Scene_Base
    include MOG_SCENE_TITLE_A

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Start
    #--------------------------------------------------------------------------
    def start
    super
    RPG::BGM.fade(500)

    @logo_active = LOGO

    SceneManager.clear

    @phase = 1
    @phase_time = -1
    dispose_title_sprites
    create_logo if @logo_active
    create_command_window
    create_commands
    create_background
    create_light
    create_cursor
    create_animated_object
    create_flash_select
    create_multiple_layers

    ##DAVE INTRO LOGO
    RPG::SE.new("Wind1", 100, 100).play



    play_title_music unless @logo_active
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Create Flash Select
    #--------------------------------------------------------------------------
    def create_flash_select
    return if !CURSOR_FLASH_SELECTION
    @flash_select = Sprite.new
    @flash_select.bitmap = Cache.title2("Cursor2")
    @flash_select.z = 99
    @flash_select.opacity = 0
    @flash_select.blend_type = CURSOR_FLASH_SLECTION_BLEND_TYPE
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Create Multiple Layers
    #--------------------------------------------------------------------------
    def create_multiple_layers
    @m_layers = []
    index = 0
    for i in MULTIPLE_LAYERS
    @m_layers.push(Multiple_Layers_Title.new(i[0],i[1],i[2],i[3],index))
    index += 1
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Create Animated Object (LOGO)
    #--------------------------------------------------------------------------
    def create_animated_object
    ###0
    @object_index = 0
    @object_animation_speed = 0
    @object = Sprite.new
    @object.z = 98
    @object.opacity = 0
    @object.blend_type = ANIMATED_SPRITE_BLEND_TYPE
    @object.zoom_x = ANIMATED_SPRITE_ZOOM
    @object.zoom_y = ANIMATED_SPRITE_ZOOM
    @object_image = Cache.title2("Animated")
    @object_frame_max = @object_image.width / @object_image.height
    @object_width = @object_image.width / @object_frame_max
    @object.bitmap = Bitmap.new(@object_width,@object_image.height)
    @object.x = ANIMATED_SPRITE_POSITION[0]
    @object.y = ANIMATED_SPRITE_POSITION[1]
    make_object_bitmap

    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Create_Logo
    #--------------------------------------------------------------------------
    def create_cursor
    @cursor = Sprite.new
    @cursor.bitmap = Cache.title2("Cursor")
    @cursor.opacity = 0
    @cursor.z = 130
    @cursor_position = [0,0]
    @mx = [0,0,0]
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Create_Logo
    #--------------------------------------------------------------------------
    def create_logo
    @phase = 0
    @logo = Sprite.new
    @logo.bitmap = Cache.title2("Logo")
    @logo.opacity = 0
    @logo_duration = 180 + (LOGO_DURATION * 60)
    @logo.z = 200
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Create Commands
    #--------------------------------------------------------------------------
    def create_commands
    @command_window.visible = false
    @commands_index_old = -1
    @commands = []
    @commands_shake_duration = 0
    index = 0
    for com in 0...6
    sprite = Sprite.new
    case index
    when 0; com_name = "New Game"
    when 1; com_name = "Continue"
    when 2; com_name = "Tutorial"
    when 3; com_name = "Oracle"
    when 4; com_name = "Credits"
    when 5; com_name = "TOS"
    end
    sprite.bitmap = Cache.title2(com_name.to_s) rescue nil
    if sprite.bitmap == nil
    sprite.bitmap = Bitmap.new(200,28)
    sprite.bitmap.font.size = 24
    sprite.bitmap.font.bold = false
    sprite.bitmap.font.italic = false
    sprite.bitmap.draw_text(0, 0, 200, 24, com_name.to_s,1)
    end
    sprite.x = COMMANDS_POS[0] - 50 - (index * 20)
    sprite.y = index * sprite.bitmap.height + COMMANDS_POS[1]
    sprite.z = 100 + index
    sprite.opacity = 0
    index += 1
    @commands.push(sprite)
    end
    @command_max = index
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > create_background
    #--------------------------------------------------------------------------
    def create_background
    @rand_title_duration = 120
    @old_back_index = 0
    @sprite1 = Plane.new
    @sprite1.opacity = 0
    @sprite1.z = 1
    if RAMDOM_SELECTION
    execute_random_picture(false)
    else
    execute_random_picture(true)
    end
    @sprite2 = Sprite.new
    @sprite2.bitmap = Cache.title2($data_system.title2_name)
    @sprite2.z = 140
    @sprite2.opacity = 0
    if TITLE_WAVE
    @sprite2.wave_amp = TITLE_WAVE_CONFIG[0]
    @sprite2.wave_length = TITLE_WAVE_CONFIG[1]
    @sprite2.wave_speed = TITLE_WAVE_CONFIG[2]
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Create Light
    #--------------------------------------------------------------------------
    def create_light
    return unless PARTICLE
    @light_bitmap =[]
    for i in 0...20
    @light_bitmap.push(Particle_Title.new(nil))
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > dispose Background1
    #--------------------------------------------------------------------------
    def dispose_background1
    @sprite1.bitmap.dispose
    @sprite1.bitmap = nil
    @sprite1.dispose
    @sprite1 = nil
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Dispose Background2
    #--------------------------------------------------------------------------
    def dispose_background2
    if @sprite2.bitmap != nil
    @sprite2.bitmap.dispose
    @sprite2.bitmap = nil
    @sprite2.dispose
    @sprite2 = nil
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Dispose Light
    #--------------------------------------------------------------------------
    def dispose_light
    return unless PARTICLE
    if @light_bitmap != nil
    for i in @light_bitmap
    i.dispose
    end
    @light_bitmap = nil
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Dispose Logo
    #--------------------------------------------------------------------------
    def dispose_logo
    return unless @logo_active
    @logo.bitmap.dispose
    @logo.dispose
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Dispose Multiple Layers
    #--------------------------------------------------------------------------
    def dispose_multiple_layers
    return if @m_layers == nil
    @m_layers.each {|layer| layer.dispose }
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Terminate
    #--------------------------------------------------------------------------
    def terminate
    super
    dispose_title_sprites
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Dispose Title Sprites
    #--------------------------------------------------------------------------
    def dispose_title_sprites
    return if @cursor == nil
    dispose_background1
    dispose_background2
    dispose_light
    dispose_logo
    dispose_multiple_layers
    @cursor.bitmap.dispose
    @cursor.dispose
    @cursor = nil
    if @flash_select != nil
    @flash_select.bitmap.dispose
    @flash_select.dispose
    end
    for com in @commands
    com.bitmap.dispose
    com.dispose
    end
    if ANIMATED_SPRITE
    @object.bitmap.dispose
    @object.dispose
    @object_image.dispose
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update
    #--------------------------------------------------------------------------
    def update
    super
    update_logo
    update_initial_animation
    update_command
    update_background
    update_light
    update_object_animation
    update_multiple_layers
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update Multiple Layers
    #--------------------------------------------------------------------------
    def update_multiple_layers
    return if @m_layers == nil
    @m_layers.each {|layer| layer.update }
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Make Object bitmap
    #--------------------------------------------------------------------------
    def make_object_bitmap
    @object.bitmap.clear
    src_rect_back = Rect.new(@object_width * @object_index, 0,@object_width,@object_image.height)
    @object.bitmap.blt(0,0, @object_image, src_rect_back)
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update Object Animation
    #--------------------------------------------------------------------------
    def update_object_animation
    return if !ANIMATED_SPRITE
    @object.opacity += 2
    @object_animation_speed += 1
    if @object_animation_speed > ANIMATED_SPRITE_SPEED
    @object_animation_speed = 0
    @object_index += 1
    @object_index = 0 if @object_index >= @object_frame_max
    make_object_bitmap
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update Cursor Position
    #--------------------------------------------------------------------------
    def update_cursor_position
    @cursor.opacity += 25
    execute_animation_s
    execute_cursor_move(0,@cursor.x,@cursor_position[0] + @mx[1])
    execute_cursor_move(1,@cursor.y,@cursor_position[1])
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Execute Animation S
    #--------------------------------------------------------------------------
    def execute_animation_s
    @mx[2] += 1
    return if @mx[2] < 4
    @mx[2] = 0
    @mx[0] += 1
    case @mx[0]
    when 1..7; @mx[1] += 1
    when 8..14; @mx[1] -= 1
    else
    @mx[0] = 0
    @mx[1] = 0
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Execute Cursor Move
    #--------------------------------------------------------------------------
    def execute_cursor_move(type,cp,np)
    sp = 5 + ((cp - np).abs / 5)
    if cp > np
    cp -= sp
    cp = np if cp < np
    elsif cp < np
    cp += sp
    cp = np if cp > np
    end
    @cursor.x = cp if type == 0
    @cursor.y = cp if type == 1
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update Logo
    #--------------------------------------------------------------------------
    def update_logo
    return if @phase != 0
    loop do
    break if @logo_duration == 0
    execute_logo
    Graphics.update
    Input.update
    end
    play_title_music
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Execute Logo
    #--------------------------------------------------------------------------
    def execute_logo
    if @logo_duration > 120 and (Input.trigger?:)C) or Input.trigger?:)B))
    @logo_duration = 120
    end
    @logo_duration -= 1
    if @logo_duration > 120
    @logo.opacity += 50
    else
    @logo.opacity -= 50
    end
    if @logo.opacity <= 0
    @logo_duration = 0
    @phase = 1
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update Background
    #--------------------------------------------------------------------------
    def update_background
    @sprite1.ox += RANDOM_PICTURES_SCROLL_SPEED[0]
    @sprite1.oy += RANDOM_PICTURES_SCROLL_SPEED[1]
    @sprite2.opacity += 25
    @sprite2.update
    return if RANDOM_PICTURES.size < 1
    @rand_title_duration -= 1
    if @rand_title_duration <= 0
    @sprite1.opacity -= 5 unless RANDOM_PICTURES.size < 2
    else
    @sprite1.opacity += 5
    end
    return if @sprite1.opacity != 0
    execute_random_picture
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Execute Random Picture
    #--------------------------------------------------------------------------
    def execute_random_picture(initial = false)
    @rand_title_duration = [[60 * RANDOM_PICTURES_DURATION, 9999].min, 60].max
    if @sprite1.bitmap != nil
    @sprite1.bitmap.dispose
    @sprite1.bitmap = nil
    end
    if RAMDOM_SELECTION
    rand_pic = rand(RANDOM_PICTURES.size)
    if rand_pic == @old_back_index
    rand_pic += 1
    rand_pic = 0 if rand_pic >= RANDOM_PICTURES.size
    end
    @old_back_index = rand_pic
    else
    @old_back_index += 1 unless initial
    @old_back_index = 0 if @old_back_index >= RANDOM_PICTURES.size
    end
    pic = RANDOM_PICTURES[@old_back_index]
    @sprite1.bitmap = Cache.title1(pic) rescue nil
    @sprite1.bitmap = Cache.title1("") if @sprite1.bitmap == nil
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update Light
    #--------------------------------------------------------------------------
    def update_light
    return unless PARTICLE
    if @light_bitmap != nil
    for i in @light_bitmap
    i.update
    end
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update Initial Animation
    #--------------------------------------------------------------------------
    def update_initial_animation
    return if @phase != 1
    @phase_time -= 1 if @phase_time > 0
    if @phase_time == 0
    @phase = 2
    @phase_time = 30
    end
    for i in @commands
    index = 0
    if i.x < COMMANDS_POS[0]
    i.x += 5 + (2 * index)
    i.opacity += 10
    if i.x >= COMMANDS_POS[0]
    i.x = COMMANDS_POS[0]
    i.opacity = 255
    if @phase_time < 15 / 2
    @phase_time = 15
    end
    end
    end
    index += 1
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update Command
    #--------------------------------------------------------------------------
    def update_command
    return if @phase != 2
    update_command_slide
    update_cursor_position
    update_flash_select
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update Command Slide
    #--------------------------------------------------------------------------
    def update_command_slide
    if @commands_index_old != @command_window.index
    @commands_index_old = @command_window.index
    @commands_shake_duration = 30
    if @flash_select != nil
    @flash_select.opacity = 255
    end
    end
    return if @commands_shake_duration == 0
    @commands_shake_duration -= 1 if @commands_shake_duration > 0
    @commands_shake_duration = 0 if !COMMAND_SHAKE
    for i in @commands
    if (i.z - 100) == @command_window.index
    i.opacity += 10
    @cursor_position = [COMMANDS_POS[0] + CURSOR_POS[0],i.y + CURSOR_POS[1]]
    i.x = COMMANDS_POS[0] + rand(@commands_shake_duration)
    else
    i.opacity -= 7 if i.opacity > 100
    i.x = COMMANDS_POS[0]
    end
    end
    end

    #--------------------------------------------------------------------------
    # ● CLASS: Scene_Title > Update Flash Select
    #--------------------------------------------------------------------------
    def update_flash_select
    return if !CURSOR_FLASH_SELECTION
    @flash_select.opacity -= 8
    @flash_select.x = @cursor_position[0] + CURSOR_FLASH_SLECTION_POS[0]
    @flash_select.y = @cursor_position[1] + CURSOR_FLASH_SLECTION_POS[1]
    end

    end

    $mog_rgss3_animated_title_a = true

    #3: CREDITS SCRIPT
    #==============================================================================
    # +++ MOG&DP - Animated Gameover (v2.4) Unofficial+++
    #==============================================================================
    # Original By Moghunter
    # Edited By: Dark Paladin For Game Over Scene.
    # http://www.atelier-rgss.com/
    # http://dpalpro.blogspot.com/
    #==============================================================================
    # Animated Gameover screen with logo, random pictures and other visual effects.
    #==============================================================================


    #==============================================================================
    # Necessary Images
    #==============================================================================
    # Place all images in Graphics/Gameover/
    #
    # Particle.png (Opcional)
    # Animated.png (Opcional) Can change name
    #==============================================================================

    module GAMEOVER_CREDITS
    #--------------------------------------------------------------------------
    # ▼ module:GAMEOVER_CREDITS > RANDOM BACKGROUND ▼
    #--------------------------------------------------------------------------
    #Picture config
    #--------------------------------------------------------------------------
    RANDOM_PICTURES = [
    "Title00", "Title01", "Title02", "Title03","Title04","Title05",
    "Title06","Title07","Title08","Title09","Title10","Title11"
    ]
    #Time between random image transition.
    RANDOM_PICTURES_DURATION = 5#(sec)
    #Use random images true/false.
    RAMDOM_SELECTION = false
    #Speed of Picture scrolling. (Speed X , Speed Y)
    RANDOM_PICTURES_SCROLL_SPEED = [0,0]

    #--------------------------------------------------------------------------
    # ▼ module:GAMEOVER_CREDITS > MULTIPLE layers ▼
    #--------------------------------------------------------------------------
    # Config for multiple layers. (There is no limit to how many)
    # usadas)
    #--------------------------------------------------------------------------
    # MULTIPLE_layers = [ ["A",B,C,D], ["A",B,C,D], ["A",B,C D], ["A",B,C,D ], ....]
    #
    # A - Name of the image
    # B - Speed of Horizontal Scroll.
    # C - Speed of Vertical Scroll.
    # D - Type of Blending. (0 - Normal / 2 - Add / 3 - Substract)
    #
    MULTIPLE_layers = [
    ["layer1",-4,0,0],
    ["layer2",0,-4,1],
    ["layer3",0,1,0]
    ]
    end

    #==============================================================================
    # ■ Module Cache > Cache Extension
    #==============================================================================
    module Cache
    def self.gameover(filename)
    load_bitmap("Graphics/Titles1/", filename)
    end
    end


    #==============================================================================
    ##==============================================================================
    ##==============================================================================
    # ■ Window TitleCommand
    #==============================================================================
    class Window_TitleCommand < Window_Command
    attr_reader :list
    end

    #==============================================================================
    #==============================================================================
    #==============================================================================
    # ■ CLASS Multiple layers Title
    #==============================================================================
    class Multiple_layers_Title
    include GAMEOVER_CREDITS
    #--------------------------------------------------------------------------
    # ● Multiple_layers_Title > Initialize
    #--------------------------------------------------------------------------
    def self.gameover(filename)
    load_bitmap("Graphics/Titles1/", filename)
    end
    def initialize(name = "", scroll_x = 0, scroll_y = 0, blend = 0, index = 0)
    @layer = Plane.new
    @layer.bitmap = Cache.gameover(name.to_s) rescue nil
    @layer.bitmap = Bitmap.new(32,32) if @layer.bitmap == nil
    @layer.z = 20 + index
    @layer.opacity = 0
    @layer.blend_type = blend
    @scroll_speed = [scroll_x, scroll_y]
    end

    #--------------------------------------------------------------------------
    # ● Multiple_layers_Title > Dispose
    #--------------------------------------------------------------------------
    def dispose
    # @layer.opacity = 0
    if @layer.bitmap
    @layer.bitmap.clear
    @layer.bitmap = nil
    end
    # @layer.dispose
    end

    #--------------------------------------------------------------------------
    # ● Multiple_layers_Title > Update
    #--------------------------------------------------------------------------
    def update
    @layer.opacity += 25
    @layer.ox += @scroll_speed[0]
    @layer.oy += @scroll_speed[1]
    end

    end

    #==============================================================================
    #==============================================================================
    #==============================================================================
    # ■ CLASS Scene Gameover
    #==============================================================================
    class Scene_Gameover < Scene_Base
    include GAMEOVER_CREDITS
    # --------------------------------------------------------------------------
    # ● Scene_Gameover > Start
    #--------------------------------------------------------------------------
    def start
    super
    RPG::BGM.fade(500)
    SceneManager.clear
    @phase = 1
    @phase_time = -1
    #dispose_all_sprites
    create_background
    create_multiple_layers
    ##play music
    Audio.bgm_play("Audio/BGM/Joyjoi", 100, 100)
    RPG::BGM.new("Joyjoi", 100, 100).play
    end

    #--------------------------------------------------------------------------
    # ● Scene_Gameover > Create Multiple layers
    #--------------------------------------------------------------------------
    def create_multiple_layers
    @m_layers = []
    index = 10
    for i in MULTIPLE_layers
    @m_layers.push(Multiple_layers_Title.new(i[0],i[1],i[2],i[3],index))
    index += 1
    end
    end

    #--------------------------------------------------------------------------
    # ● Scene_Gameover > create_background
    #--------------------------------------------------------------------------
    def create_background
    @rand_title_duration = 120
    @old_back_index = 0
    @sprite1 = Plane.new
    @sprite1.opacity = 0
    @sprite1.z = 11
    if RAMDOM_SELECTION
    execute_random_picture(false)
    else
    execute_random_picture(true)
    end
    end

    #--------------------------------------------------------------------------
    # ● Scene_Gameover > dispose Background1
    #--------------------------------------------------------------------------
    def dispose_background1
    @sprite1.bitmap.dispose
    @sprite1.bitmap = nil
    @sprite1.dispose
    @sprite1 = nil
    #SceneManager.clear

    ###@sprite.bitmap.dispose
    ###@sprite.dispose
    end

    #--------------------------------------------------------------------------
    # ● Scene_Gameover > Dispose Multiple layers
    #--------------------------------------------------------------------------
    def dispose_multiple_layers
    return if @m_layers == nil
    @m_layers.each {|layer| layer.dispose }
    end

    #--------------------------------------------------------------------------
    # ● Scene_Gameover > Terminate
    #--------------------------------------------------------------------------
    def terminate
    super
    dispose_all_sprites
    goto_title
    end

    #--------------------------------------------------------------------------
    # ● Scene_Gameover > Dispose Title Sprites
    #--------------------------------------------------------------------------
    def dispose_all_sprites
    dispose_background1
    dispose_multiple_layers
    end

    #--------------------------------------------------------------------------
    # ● Scene_Gameover > Update
    #--------------------------------------------------------------------------
    def update
    super
    update_background
    update_multiple_layers
    terminate if Input.trigger?:)C)

    end

    #--------------------------------------------------------------------------
    # ● Scene_Gameover > Update Multiple layers
    #--------------------------------------------------------------------------
    def update_multiple_layers
    return if @m_layers == nil
    @m_layers.each {|layer| layer.update }
    end

    #--------------------------------------------------------------------------
    # ● Scene_Gameover > Make Object bitmap
    #--------------------------------------------------------------------------
    def make_object_bitmap
    @object.bitmap.clear
    src_rect_back = Rect.new(@object_width * @object_index, 0,@object_width,@object_image.height)
    @object.bitmap.blt(0,0, @object_image, src_rect_back)
    end

    #--------------------------------------------------------------------------
    # ● Scene_Gameover > Update Background
    #--------------------------------------------------------------------------
    def update_background
    @sprite1.ox += RANDOM_PICTURES_SCROLL_SPEED[0]
    @sprite1.oy += RANDOM_PICTURES_SCROLL_SPEED[1]

    return if RANDOM_PICTURES.size < 1
    @rand_title_duration -= 1
    if @rand_title_duration <= 0
    @sprite1.opacity -= 5 unless RANDOM_PICTURES.size < 2
    else
    @sprite1.opacity += 5
    end
    return if @sprite1.opacity != 0
    execute_random_picture
    end


    #--------------------------------------------------------------------------
    # ● Scene_Gameover > Execute Random Picture
    #--------------------------------------------------------------------------
    def execute_random_picture(initial = false)
    @rand_title_duration = [[60 * RANDOM_PICTURES_DURATION, 9999].min, 60].max
    if @sprite1.bitmap != nil
    @sprite1.bitmap.dispose
    @sprite1.bitmap = nil
    end
    if RAMDOM_SELECTION
    rand_pic = rand(RANDOM_PICTURES.size)
    if rand_pic == @old_back_index
    rand_pic += 1
    rand_pic = 0 if rand_pic >= RANDOM_PICTURES.size
    end
    @old_back_index = rand_pic
    else
    @old_back_index += 1 unless initial
    @old_back_index = 0 if @old_back_index >= RANDOM_PICTURES.size
    end
    pic = RANDOM_PICTURES[@old_back_index]
    @sprite1.bitmap = Cache.gameover(pic) rescue nil
    @sprite1.bitmap = Cache.gameover("") if @sprite1.bitmap == nil
    end

    end


    $mog_rgss3_animated_go_a = true

    Ok, so be gentle :)
    What am I missing, seems fundamental to understanding Ruby.

    All advice greatly received.
     
    #1
  2. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,359
    Likes Received:
    10,405
    First Language:
    English
    Primarily Uses:
    RMVXA
    Scripts is where people can post scripts they have written to share with the community, not where queries can be raised, unless they relate to a script already posted here.

    I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #2
    boyflea likes this.
  3. Trihan

    Trihan Speedy Scripter Veteran

    Messages:
    1,483
    Likes Received:
    975
    Location:
    Buckie, Scotland
    First Language:
    English
    It seems like @sprite1 has already been disposed elsewhere at some point so it's trying to access the property of a variable that no longer contains any data.
     
    #3
    boyflea likes this.
  4. boyflea

    boyflea boyflea Veteran

    Messages:
    51
    Likes Received:
    14
    Location:
    Southampton, England
    First Language:
    English
    Primarily Uses:
    RMVXA
    thanks for your reply! It put me on the right path!
    Ok, so I checked again, and tehre werw two seperate calls being made:

    FYI:
    in CREDITS SCRIPT, 3: Scene_Gameover > Execute Random Picture

    this existed:
    if @sprite1.bitmap != nil
    @sprite1.bitmap.dispose
    @sprite1.bitmap = nil


    so replaced with
    dispose_background1

    as this is the one place I should be getting rid of the backgournd: and that fixed it.
    little lesson learned when adopting someone else's code - check everything that's making calls :)

    anyway, hope this query helps other people in some small way. :)

    thanks again - I'll credit you guys in my upcoming epic game!
    [though tbh, if anyone adds ' me too' below, I'd probably ad them too: ;) ]
     
    #4

Share This Page