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.

Adding text as bitmap on screen - simple question!

Hi, I am having a problem and the manual is not helping!

I want to add a simple little text message on the screen when you perform certain actions, such as when doing a skill (fishing, mining) I want it to show something like Fishing skill +1 ! over the actor.

I thought this would be very similar to how ABS show attack points on the screen when you hit a monster, so I've been staring at the code for sever ABS scripts for ages and I cannot see how!

This is what I have so far.. but it doesn't work :(

Code:
bitmap = Bitmap.new(10, 10) # I don't know how to make this on the actor
bitmap.draw_text(100, 100, 160, 20, "Fishing Skill + 1 !, 1) # Changing these numbers around doesn't help

What am I missing?! Thanks!
 
Hi, thanks for your input, can't believe I missed the quotation mark, but it still does not work! I think the coords are just all wrong, I have no idea how to get it somewhere on screen.

And even if it worked, I would like to show the message above the player's head, can anyone tell me how to do this?

The code I wrote earlier, even with your corrections, does nothing.
 
You could use this class I created for displaying text on screen

Code:
class Sprite_Text < Sprite
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :text
  attr_reader :width
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(text, x = 0, y = 0, viewport = nil)
    # Call Sprite#initialize and send viewport
    super(viewport)
    # Set Coordinates
    self.x, self.y = x, y
    # Set Bitmap
    self.bitmap = Bitmap.new(32, 32)
    # Set Text
    @text = text
    # Setup Text
    setup_text
  end
  #--------------------------------------------------------------------------
  # * Set Text
  #--------------------------------------------------------------------------
  def text=(text)
    # Retunr if same text
    return if @text == text
    # Set New Text
    @text = text
    # Setup Text
    setup_text
  end
  #--------------------------------------------------------------------------
  # * Set Width
  #--------------------------------------------------------------------------
  def width=(width)
    # Retunr if same width
    return if @width == width
    # Set New Width
    @width = width
    # Setup Text
    setup_text
  end
  #--------------------------------------------------------------------------
  # * Setup Text (Private)
  #--------------------------------------------------------------------------
  private
  def setup_text
    # Get Size of Text
    size = bitmap.text_size(@text).width
    # Dispose Previous Bitmap
    self.bitmap.dispose if self.bitmap != nil
    # Create Bitmap
    self.bitmap = Bitmap.new(@width.nil? ? size : @width, 32)
    # Draw Text onto bitmap
    self.bitmap.draw_text(0, 0, size, 32, @text)
  end
end

You just can't display a Bitmap object on screen you have to create a Sprite object to display it on the screen as well

Note: to get the player's coordinates just do
$game_player.screen_x $game_player.screen_y
 
Hi, thank you so much for letting me use that class but I have a really dumb question...

So I put that in my project as a Script yes? Then how do I use it, can you tell me the simplest thing - how do I make it so I press Space on an NPC and it says over my actor's body "Test!" or something?
 

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