Hi guys, how are you? I've been filtering messages with the "click" word inside them and I've found few information(also the documentation tells almost nothing about) related to this topic. What I understood from reading this posts is that there's a way to show the mouse cursor which is capturing where it is(x and y) and drawing an image there, representing the cursor, that's all I have found.
My question is: it's possible to make a game which works with mouse clicks? if it's possible, how can I do? which is the best way to face this problem?
Thank you for your time :)
Good information, thanks. How can I do to show up the mouse cursor over the window? Is there a flag to set to show the default OS cursor on Gosu window or something...?
Yeah, I recommend using the system cursor because it's easy. Just override
in your Window class:
Great! thank you! Now the final related thing I need to know: how can I overwrite the cursor image, to show my own personal cursor image?
class Game < Window
super 640, 480, false
# load your custom cursor image:
@cursor = Image.new(self, "cursor.png", false)
# your game logic here
# draw the cursor image in mouse_x, mouse_y:
@cursor.draw(self.mouse_x, self.mouse_y, 1)
You dont need to override
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_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
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.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill