Save-Point
How to remove an image from a window? - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Code Support (https://www.save-point.org/forum-20.html)
+--- Thread: How to remove an image from a window? (/thread-2177.html)



How to remove an image from a window? - computerwizoo7 - 07-12-2009

I am making a simple map system where the player opens a window which shows the player a picture of a world map for the game, however when i dispose of the window the image won't go away, it waits until rmxp clears it from the screen.

how can i fix this to dispose of the window of soon as the window is disposed of?

here is the script:

Code:
class Window_Map < Window_Base
  def initialize
    super(0,0,640,480)
    self.contents = Bitmap.new(width-32,height-32)
    self.contents.font.name = "Arial"
    self.contents.font.size = 24
    refresh
  end
    
  def refresh
    self.contents.clear
    @Map_Image = Sprite.new
    @Map_Image.bitmap = RPG::Cache.picture("Map_Color.png")
    @Map_Image.z = 100
  end
end

Code:
class Map_Scene
  
  def main
    @Map = Window_Map.new
    
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        then break
      end
    end
    
    Graphics.freeze
    @Map.dispose
    
  end
  
  def update
    
    @Map.update
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
    end
  end
  
end



[Resolved] How to remove an image from a window? - DerVVulfman - 07-12-2009

Maybe you should try this...
Replace:
Code:
@Map.dispose
with
Code:
@Map.dispose unless @Map == nil
which only disposes @Map if it still exists.

Now replace:
Code:
if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
    end

Code:
if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @Map.dispose unless @Map == nil
      @Map = nil
      $scene = Scene_Map.new
    end
Which can delete/dispose of @map on the keypress. After that, I set it to 'nil' so IF it is disposed this way, the system won't try to dispose it again at the end of the main routine.


[Resolved] How to remove an image from a window? - computerwizoo7 - 07-12-2009

It still won't remove the image when the button is pressed, then it waits until rmxp removes the image.
at first glance it seems that your suggestion would have worked by assigning nothing to the @Map but it still don't work.
do you have anymore ideas as to solve this problem?

If i clear the RPG ::Cache will that work if so how to i put in the code because i tried it in the update and in the Main.


[Resolved] How to remove an image from a window? - Charlie Fleed - 07-12-2009

That's because the actual image is never disposed. Add this.

Code:
class Window_Map < Window_Base
  def dispose
    super
    @Map_Image.dispose
  end
end



[Resolved] How to remove an image from a window? - computerwizoo7 - 07-12-2009

Thanks Charlie Lee, that one worked.
so you have to dispose of images like that in rmxp or are there other ways of doing it?


[Resolved] How to remove an image from a window? - Charlie Fleed - 07-13-2009

To my knowledge calling .dispose is the only way when you are deleting the window together with the image in it.
If you only want to make them temporarily disappear, you can use the visible attribute and link the image's one to the window's one with a piece of code similar to this one:

Code:
class Window_Map < Window_Base
  def visible=(value)
    @visible=value
    @Map_Image.visible=value
  end
end

though it might be different depending on the cases.


[Resolved] How to remove an image from a window? - computerwizoo7 - 07-13-2009

Thanks for the info, it is very useful!