04-21-2014, 06:46 PM
Perhaps, you may wish to have this minor script-ette? Pardon possible syntax errors... I'm writing it from work, so I am actually unsure about the Icon Cache statement. *sigh*
This script add-on should allow you to draw an icon within a centered area, the icon's own width and height adjusting placement as it loads. As I put it within the Window_Base class, it should be accessible from virtually any window scripts that has it as a parent class (most all are).
AND... you don't have a size limit for your icons. Could be used as a basis for other pictures too. Also, if no filename is present... it won't blit.
This script add-on should allow you to draw an icon within a centered area, the icon's own width and height adjusting placement as it loads. As I put it within the Window_Base class, it should be accessible from virtually any window scripts that has it as a parent class (most all are).
AND... you don't have a size limit for your icons. Could be used as a basis for other pictures too. Also, if no filename is present... it won't blit.
Code:
class Window_Base
#------------------------------------------------------------------
# * Draw centered icon in place
# x : x-location (assuming center coordinates)
# y : y-location (assuming center coordinates)
# filename : icon filename
#------------------------------------------------------------------
def centered_icon(x, y, filename=nil)
# exit out if no file exists or is empty string
return if filename.nil?
return if filename = ""
# Acquire the bitmap
bitmap = RPG::Cache.icons(iconfile)
# Adjust target coords based on bitmap size (half each)
dest_x = x - (bitmap.width/2).to_i
dest_y = y - (bitmap.height/2).to_i
# create destination rectangle based on full bitmap size
dest_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
# Blit image into centered position
self.contents.blt(dest_x, dest_y, bitmap, dest_rect)
end
end