Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

world map script bug (?) command to remove picture from screen

Hi people!:) Can somebody help me solving this problem?
I'm using a world map script that shows off a map picture on screen.
Here it is (thanks for its author, Daniel_Maximus2):

#===============================================================================

#-------------------------------------------------------------------------------
# - Map Item Script
#-------------------------------------------------------------------------------
#===============================================================================

#
# - Shows a map and compass in the screen
# - Made by - Daniel_Maximus2
# Cardinalis Corp (R)
# - Script free for personal use since included the name and the team
# of the creator
# - Compatibility with many Scripts. See instructions for more information
#
# - Put the pictures in the folder Graphics/Pictures/Mapa (create the folder Mapa)
# - A map of 640x380
# - A compass of 60x60 (different sizes changes lines 81 and 82)
# - A picture of 640x3 (linha y)
# - A picture of 3x380 (linha x)
# - Created in 12-14-06
#
# classes: Window_Mapa
# Window_Text
# Scene_Mapa
#
#-------------------------------------------------------------------------------
#===============================================================================


COMPASS = 8 #id of Compass
MAP = 7 #id of Map
VAR_MAP_X = 4 #$game_variable[id] that stores X cordinate
VAR_MAP_Y= 5 #$game_variable[id] that stores Y cordinate
WORLDCENTERX = 240 #World center X (Optional)
WORLDCENTERY = 300 #World center Y (Optional)
# If you do not define a cordinate for center of the world, delete lines 142
# to 172 and activate lines 173 e 174.

#===============================================================================

#-------------------------------------------------------------------------------
# - Window_Mapa
#-------------------------------------------------------------------------------
#===============================================================================


class Window_Mapa < Window_Base
def initialize
super(0, 65, 640, 416)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
self.opacity = 0
refresh
end
def refresh
# variables that stores cordinates (Events/Paralell Process)
@wx = $game_variables[VAR_MAP_X]
@wy = $game_variables[VAR_MAP_Y]
@f_linex = @wx #cord x
@f_liney = @wy #cord y

# Draw the map ========================================================
@map = Sprite.new
@map.bitmap = RPG::Cache.picture("Mapa/worldmap.jpg")#Name of map file
@map.x = 0
@map.y = 65
# Draw the map ========================================================

# Draw the compass, if have ========================================
if $game_party.item_number(COMPASS) > 0
@i_linex = Sprite.new
@i_linex.bitmap = RPG::Cache.picture("Mapa/compasso_x.png")#Name of line x file
@i_linex.x = @map.x
@i_linex.y = @map.y

@i_liney = Sprite.new
@i_liney.bitmap = RPG::Cache.picture("Mapa/compasso_y.png")#Name of line y file
@i_liney.x = @map.x
@i_liney.y = @map.y

@compass = Sprite.new
@compass.bitmap = RPG::Cache.picture("Mapa/compasso.png")#Name of compass file
@cwid = 30 #half of compass width
@chei = 30 #half of compass height
@compass.x = @map.x - @cwid
@compass.y = @map.y - @chei
end
end
# Fim ======================================================================
def move_compass
correctx = @f_linex - @i_linex.x
correcty = @f_liney - @i_liney.y
correctcompx = @wx - @cwid - @compass.x
correctcompy = @wy - @chei - @compass.y
#====================
if @i_linex.x < (@f_linex - 10)
@i_linex.x += 10
end
if @i_linex.x >= (@f_linex - 10)
@i_linex.x += correctx
end
#====================
if @i_liney.y < (@f_liney - 10)
@i_liney.y += 10
end
if @i_liney.y >= (@f_liney - 10)
@i_liney.y += correcty
end
#====================
if @compass.x < (@wx - 10 - @cwid)
@compass.x += 10
end
if @compass.x >= (@wx - 10 - @cwid)
@compass.x += correctcompx
end
#====================
if @compass.y < (@wy - 10 - @chei)
@compass.y += 10
end
if @compass.y >= (@wy - 10 - @chei)
@compass.y += correctcompy
end
#====================
end
end

#===============================================================================

#-------------------------------------------------------------------------------
# - Mapa_Text - Write the location
#-------------------------------------------------------------------------------
#===============================================================================

class Game_Map

def name
$map_infos[@map_id]
end
end
class Scene_Title
$map_infos = load_data("Data/MapInfos.rxdata")
for key in $map_infos.keys
$map_infos[key] = $map_infos[key].name
end
end

class Mapa_Text < Window_Base
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = 200#
refresh
end
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.font.size = $fontsize
text = "Your location: #{$game_map.name}."
self.contents.draw_text(4, 0, self.width - 40, 32, text)
end
end

#===============================================================================

#-------------------------------------------------------------------------------
# - Scene_Mapa
#-------------------------------------------------------------------------------
#===============================================================================


class Scene_Mapa
def main
@help_window = Mapa_Text.new
@mapa_window = Window_Mapa.new
Graphics.transition
loop do
Graphics.update
Input.update
update
if $game_party.item_number(COMPASS) > 0
@mapa_window.move_compass
end
if $scene != self
break
end
end
Graphics.freeze
@help_window.dispose
@mapa_window.dispose
end

#-------------------------------------------------------------------------------
# - Update
#-------------------------------------------------------------------------------

def update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu.new(0)
return
end
end
end

the problem is, whenever I use the map item and the picture appears,
when I return to game the pic don't fade out and continue to be shown on screen, even if I return to title screen!

http://www.imagehosting.com/out.php/t11 ... ground.jpg[/IMG]

The question is: What command must be put into this script so the map is correctly removed from screen in the end of the process? Maybe this?:

Graphics.freeze
@help_window.dispose
@mapa_window.dispose

But it's not working. What must I do?@_@ I'll appreciate any help. ;)
 
Try adding in a @map.dispose , to that list of dispose's, that should probably fix it.

If you want to be safe i would always throw in a .dispose for each sprite in a class.
 
Maybe like this?
Graphics.freeze
@map.dispose
@help_window.dispose
@mapa_window.dispose
It's not working. It says that's a undefined method for nilclass.

In Scene_Mapa there's something like:

@help_window = Mapa_Text.new
@mapa_window = Window_Mapa.new
considering that these two elements get disposed, maybe I should write something like
"@map.something = something.new" in addition to that? (Although there isn't a specific class to get @map related to...)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top