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.

Simple HUD script request

Status
Not open for further replies.
I want a script that's compatible with the SDK and Mr.Mo's ABS, and shows a variable on the screen, with the text "%" after the variable. The variables ID should be 15. I want it so I can use a picture in the pictures folder for the appearance of it, rather than using a windowskin. Should be pretty simple.

Thanks.
 

poccil

Sponsor

I'm done.

The following functions are defined:
  • showVarDisplay(num,x,y,varnumber) - Creates a new VariableDisplay
    numbered _num_ and which is positioned on the coordinates _x_ and _y_.
    The text is set to the variable numbered _varnumber.
  • updateVarDisplays - Updates all VariableDisplays. To be called on
    Spriteset_Map's update function.
  • hideVarDisplay(num) - Closes the VariableDisplay numbered _num_.
  • getVarDisplay(num) - Gets the VariableDisplay numbered _num_.
VariableDisplay has these changeable properties:
x,y,z,opacity,visible - Work like Sprite's properties
fontface, fontsize, textcolor - Font, size, and color of the text
picture - File name of background graphic
varnumber - Variable's ID number
update - Updates the display.

Code:
class VariableDisplay
###############################
 # Default font face.
 DEFAULTFONT=Arial"
 # Default text size.
 DEFAULTSIZE=22
 # Default text color.
 DEFAULTCOLOR=Color.new(255,255,255)
 # Picture filename.  Must be in Graphics/Pictures.
 DEFAULTPICTURE="picture.png"
 # Default Z order.
 DEFAULTZ=100
###############################
 attr_reader :x,:y,:picture,:varnumber,:fontface
 attr_reader :fontsize,:textcolor,:z,:opacity,:visible
 def initialize(x,y,varnumber,picture=nil)
  @z=DEFAULTZ
  @sprite=Sprite.new(nil)
  @sprite.z=@z
  @sprite2=Sprite.new(nil)
  @sprite2.z=@z
  @picture=nil
  @picturename=picture ? picture : DEFAULTPICTURE
  @bitmap=nil
  @x=x
  @y=y
  @changeBitmap=true
  @varnumber=varnumber
  @fontface=DEFAULTFONT
  @fontsize=DEFAULTSIZE
  @textcolor=DEFAULTCOLOR
  @opacity=255
  @visible=true
  privRefresh
 end
 def dispose
  @picture.dispose
  @bitmap.dispose
  @sprite.dispose
  @sprite2.dispose
 end
 def z=(value)
  @z=value
  privRefresh
 end
 def fontsize=(value)
  @fontsize=value
  @changeBitmap=true
  privRefresh
 end
 def fontface=(value)
  @fontface=value
  @changeBitmap=true
  privRefresh
 end
 def picture=(value)
  @picture=value
  @changeBitmap=true
  privRefresh
 end
 def varnumber=(value)
  @varnumber=value
  @changeBitmap=true
  privRefresh
 end
 def textcolor=(value)
  @textcolor=value
  @changeBitmap=true
  privRefresh
 end
 def x=(value)
  @x=value
  privRefresh
 end
 def y=(value)
  @y=value
  privRefresh
 end
 def z=(value)
  @z=value
  privRefresh
 end
 def opacity=(value)
  @opacity=value
  privRefresh
 end
 def visible=(value)
  @visible=value
  privRefresh
 end
 def update
  privRefresh
 end
 private
 def privRefresh
  if @changeBitmap
   @picture.dispose if @picture
   @picture=RPG::Cache.picture(@picturename)
   @bitmap.dispose if @bitmap
   @bitmap=Bitmap.new(@picture.width,@picture.height)
   @bitmap.font.name=[@fontface,"Arial","Times New Roman]
   @bitmap.font.size=@fontsize
   @bitmap.font.color=@textcolor
   @sprite.bitmap=@picture
   @sprite2.bitmap=@bitmap
   @changeBitmap=false
  end
  @bitmap.clear
  @bitmap.draw_text(0,0,@bitmap.width,@bitmap.height,
    $game_variables[@varnumber].inspect+"%",1)
  @sprite.x=@x
  @sprite.y=@y
  @sprite.z=@z
  @sprite.opacity=@opacity
  @sprite.visible=@visible
  @sprite2.x=@x
  @sprite2.y=@y
  @sprite2.z=@z
  @sprite2.opacity=@opacity
  @sprite2.visible=@visible
 end
end

################

class Game_Temp
 attr_accessor :vardisplays
end

def showVarDisplay(num,x,y,varnumber)
 if !$game_temp.vardisplays
  $game_temp.vardisplays=[]
 end
 display=VariableDisplay.new(x,y,varnumber)
 $game_temp.vardisplays[num]=display
 return display
end
def getVarDisplay(num)
 return nil if !$game_temp.vardisplays
 return $game_temp.vardisplays[num]
end
def hideVarDisplay(num)
 display=getVarDisplay(num)
 if display
  display.dispose
  $game_temp.vardisplays[num]=nil
 end
end
def updateVarDisplays
 return if !$game_temp.vardisplays
 for display in $game_temp.vardisplays
  display.update if display
 end  
end

An optional part of the code follows, which just updates Spriteset_Map to call updateVarDisplays:

Code:
class Spriteset_Map
  alias petero_vardisplays_Spriteset_Map_update update
  def update
    updateVarDisplays
    petero_vardisplays_Spriteset_Map_update
  end
end
 

Anonymous

Guest

This topic has been resolved. If Itachi62 or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

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