By jahmaican
Date 2013-12-10 11:41
Edited 2013-12-10 11:47
Quick example:
class Game < Window
def initialize
super 640, 480, false
# load your custom cursor image:
@cursor = Image.new(self, "cursor.png", false)
end
def update
# your game logic here
end
def draw
# draw the cursor image in mouse_x, mouse_y:
@cursor.draw(self.mouse_x, self.mouse_y, 1)
end
end
You dont need to override needs_cursor?
here.
Okay, that makes sense. So, if I want to use the default OS cursor just re-define needs_cursor?(); if I want to use my own cursor icon I do what you jahmaican say, is that right? This show me that draw my own cursor is a little more expensive than the other option, don't know how much expensive, what do you think? Thank you guys, it's a great help.
The docs don't clarify this very well, but draw
method is called every time the window needs re-drawing, so by educated guess (don't rely on this description) - typically it happens after every update
cycle, but not neccessarily, e.g. it might not happen in this program if your mouse_x
and mouse_y
doesn't change.
Anyway, you shouldn't worry much about performance with single drawing method because Gosu handles it quite well and you'll be doing lots of much much more complicated operations soon.
Understood. Thanks for the help, see you around guys!
Also worth to mention that custom cursor drawn by Gosu is affected by FPS, so if game runs slow, your cursor will lag.
Default system cursor is independent from the Window so it won't lag.
Okat that's a very good advertise, thank you lol_o2 !
IIRC, #update generally happens before #draw, but #draw can also happen as the OS demands.
So sometimes you get things like
#update
#draw
#draw
but not necessarily every frame.
This is one of the reasons why you don't want to do any game logic in the #draw method, only rendering logic.
Thanks for the information RavensKrag, it's appreciated.