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.

First time scripter need help with draw.text

Hi, i'm trying to learn how to script by a simple process of cutting and pasting snippits of code around a scene i've created. I'm having a little trouble though (which i guess can be expected).

I'm using AWorks Input and MouseInput scripts to create a simple menu image that pops up and displays pictures. No 'windows' as such. When I use a mouse-over to determine if some text should display at a given location on the screen it does, however it doesnt disappear when I move the mouse off the location... still with me?
Here's a screen showing the mish-mash of text.
screen.png

Here's a look at the code, please don't rip into me for any faux pas in the scripting, im not a scripter. I'm trying to learn.
Code:
class Scene_Alt_Menu

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    @spriteset = Spriteset_Map.new

    @sprite = Sprite.new

    @sprite.bitmap = RPG::Cache.picture("men_back_char")

    # Execute transition

    Graphics.transition(5)

    # Main loop

    while $scene == self

      Graphics.update

      Input.update

      update

    end

    # Prepare for transition

    Graphics.freeze

    @sprite.bitmap.dispose

    @sprite.dispose

    # Execute transition

    Graphics.transition(5)

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

 

    menchar = Input.mouse_in_area?(341, 13, 32, 32)

    menpack = Input.mouse_in_area?(378, 13, 32, 32)

    menabil = Input.mouse_in_area?(416, 13, 32, 32)

    menally = Input.mouse_in_area?(452, 13, 49, 32)

    menmiss = Input.mouse_in_area?(506, 13, 25, 32)

    

    

    if menchar and Input.trigger?(Input::MOUSE_PRIMARY)

      $game_system.se_play($data_system.decision_se)

      @sprite.bitmap = RPG::Cache.picture("men_back_char")

    elsif menpack and Input.trigger?(Input::MOUSE_PRIMARY)

      $game_system.se_play($data_system.decision_se)

      @sprite.bitmap = RPG::Cache.picture("men_back_pack")

    elsif menabil and Input.trigger?(Input::MOUSE_PRIMARY)

      $game_system.se_play($data_system.decision_se)

      @sprite.bitmap = RPG::Cache.picture("men_back_abil")

    elsif menally and Input.trigger?(Input::MOUSE_PRIMARY)

      $game_system.se_play($data_system.decision_se)

      @sprite.bitmap = RPG::Cache.picture("men_back_ally")

    elsif menmiss and Input.trigger?(Input::MOUSE_PRIMARY)

      $game_system.se_play($data_system.decision_se)

      @sprite.bitmap = RPG::Cache.picture("men_back_miss")

    end

    

    if menchar

      @sprite.bitmap.draw_text(124, 410, 420, 32, 'Click for Character Info', 1)

    elsif menpack

      @sprite.bitmap.draw_text(124, 410, 420, 32, 'Click for Backpack Info', 1)

    elsif menabil 

      @sprite.bitmap.draw_text(124, 410, 420, 32, 'Click for Abilities Info', 1)

    elsif menally 

      @sprite.bitmap.draw_text(124, 410, 420, 32, 'Click for Allies Info', 1)

    elsif menmiss 

      @sprite.bitmap.draw_text(124, 410, 420, 32, 'Click for Missions Info', 1)

    else 

      @sprite.bitmap.draw_text(124, 410, 420, 32, ' ', 1)

    end

 

 

    # If TAB button was pressed

    if Input.press?(Keys::TAB)

      # Switch to map screen

      $scene = Scene_Map.new

    end

  end

end
my problem is with the last set of elsif commands they display the text but they dont delete it afterwards, so i get a mush of text at the bottom of my screen. All I want to know is how to make the text disappear after the mouse moves off the icon.

And yes, I'm trying to re-create the menu from Borderlands.
 
There's an important mistake in your code :
Ruby:
     @sprite = Sprite.new

    @sprite.bitmap = RPG::Cache.picture("men_back_char")

    # (...)

    @sprite.bitmap.draw_text(124, 410, 420, 32, 'Click for Character Info', 1)

 
With this code you draw text on a cached bitmap. So if, later you try to access this picture with RPG:Cache.picture (and even in another scene) you will get the picture with the text.

There's two way to resolve your problem :
- You create another sprite to draw your text and you use Bitmap#clear on it bitmap to erase it.
- You assign sprite.bitmap with a clone of the cached picture (with Object#clone, a clone is an another object so an object which modifications don't affect the original) and when you want to erase modifications you assign your sprite bitmap with another clone of the original picture =).
 

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