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.

How to show an updating variable on scene_map

I actually asked this question many moons ago (on .net) but I kinda fell off with RMXP (when the ennglish version because the standard instead of PK).

I just need to know how I can add a plain-text variable visible on the top/center of the map scene? Thanks in advance. =D
 
Ok, unfortunately I can't figure out a simple way to do this.

1) First create a plane called @text in the script you're using (use a global if you want). @text = Plane.new
2) Create a new, empty bitmap called @textBMP. @textBMP = Bitmap.new(640,480)
3) Assign the bitmap to the plane. @text.bitmap = @textBMP4) Draw the text. @text.bitmap.drawtext(x, y, 240, 64, str)

[create the plane and bitmap in the definition part of the script, ie near the top]

Code:
@text = Plane.new
@textBMP = Bitmap.new(640,480)

...

@text.bitmap.drawtext(x,y,240,64,"")
 

Jared

Member

Hm, in my opinion, a plane is to big for a simple variable-text. I would solve the problem as follows:
Code:
class Scene_Map
  VARIABLENNUMMER = 1 #Number of the variable
  alias variable_main main
  def main
    @variable_text = Show_Variable.new(VARIABLENNUMMER)
    variable_main
    @variable_text.dispose
  end
  alias variable_update update
  def update
    @variable_text.update
    variable_update
  end
end

class Show_Variable < Sprite
  #DEFAULT VALUES
  COLOR = [0, 0, 0] #White
  X = 20
  Y = 0
  #INITIALIZING
  def initialize(variable_id, x=X, y=Y, color=Color.new(*COLOR))
    super()
    @variable_id = variable_id
    self.bitmap = Bitmap.new(150, 50)
    self.x, self.y, self.z = x, y, 4999
  end
  #UPDATING/REFRESHIN
  def update
    bit = self.bitmap
    bit.clear
    bit.draw_text(0,0,bit.width, bit.height, $game_variables[@variable_id].to_s)
  end
end
 
I'd solve this by simply creating a new window which gets refreshed every frame... as everyone else posted a script in here, let me do the same...

Code:
#==============================================================================
# Scene_Map Variable Display
#------------------------------------------------------------------------------
# Script by BlueScope
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  alias vardisplay_initialize initialize
  def initialize
    vardisplay_initialize
    @variable = "Test"
  end
  #--------------------------------------------------------------------------
  alias vardisplay_main main
  def main
    @vardisplay_window = Window_Base.new(0, 0, 640, 64)
    @vardisplay_window.opacity = 0
    @vardisplay_window.contents = Bitmap.new(@vardisplay_window.width - 32, 
      @vardisplay_window.height - 32)
    @vardisplay_window.contents.draw_text(0, 0, 600, 32, @variable, 1)
    vardisplay_main
    @varidosplay_window.dispose
  end
  #--------------------------------------------------------------------------
  alias vardisplay_update update
  def update
    @vardisplay_window.contents.clear
    @vardisplay_window.contents.draw_text(0, 0, 600, 32, @variable, 1)
    vardisplay_update
  end
  #--------------------------------------------------------------------------
end

I suggest you to adjust the naming on a couple of those variables (mainly @variable ^_^ ) to make things easier for you... other than that, that thing is ready to go.

@Carlos: Bad Mr. Global User! *hits with stick* :p
 

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