I think the current version of the gosu framework doesn’t have an option to show the mouse pointer. At least, I haven’t found one ( and when I asked on gosu’s wiki, Julian said it was on the todo list ). So, I thought about drawing a mouse pointer. The only thing you’d want to be careful about is that when you draw a mouse pointer in your game ( or whatever you’re using gosu for ) is to make sure that the pointer image is the last one you’re drawing. Seems logic, right ? We’re doing this because the mouse pointer should always the top-most image.
Here’s a screenshot of how it looks like :
And the code behind it :
require "gosu"
class GameWindow < Gosu::Window
def initialize
super(640,480,false)
self.caption = "Gosu Window"
@pointer = Gosu::Image.new(self,"pointer.png",true) # we're loading a picture of the mouse
@px = @py = 0
end
def update
@px = mouse_x # this method returns the x coordinate of the mouse
@py = mouse_y # this method returns the y coordinate of the mouse
end
def draw
@pointer.draw(@px,@py,0) # we're drawing the mouse at the current position
end
end
if __FILE__ == $0
a = GameWindow.new
a.show
end
I found this to be really helpful. Thanks for putting this online. I’m using Gosu as a quick way to mock up game ideas and never would have figured out how to grab the mouse variables without this.
Hi Benton!
Glad you found this helpful! You can read more about methods present in some of the Gosu classes here
Cool!
I was thinking of quiting developing with GOSU without mouse related things..
Great tip!
Don’t quit now!
Julian said he’ll add mouse pointer support in the next release or so!