I've been having trouble centering text in the Gosu library to the absolute middle of the screen.
require 'gosu'
class GameWindow < Gosu::Window
def initialize (width=800, height=600, fullscreen=false)
super
self.caption = 'Hello'
@message = Gosu::Image.from_text(
self, 'HELLO WORLD', Gosu.default_font_name, 45)
end
def draw
@message.draw(377.5,277.5,0)
end
end
window = GameWindow.new
window.show
My first approach was to take the height of the screen, subtract it by the height of the text 45, and then divide by 2. Now that seemed to work when aligning vertically.
However, horizontally is a different story...It seems to be taking the top left corner of the text and centering it which I expected it to do, instead of the middle of the text.
Anyone got a formula for this ? I tried a whole bunch of things, and only came close.

