Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / A game with mouse input
- - By IgorJorobus Date 2013-12-09 21:25
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 :)
Parent - - By jahmaican Date 2013-12-09 21:43
You just use button_down? MsLeft etc. like you do with keyboard input. Here's the list of all possible buttons:
http://www.libgosu.org/rdoc/Gosu.html
Parent - - By IgorJorobus Date 2013-12-10 02:28
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...?
Parent - - By erisdiscord Date 2013-12-10 06:25
Yeah, I recommend using the system cursor because it's easy. Just override needs_cursor? in your Window class:

def needs_cursor?
  true
end
Parent - - By IgorJorobus Date 2013-12-10 09:53
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?
Parent - - 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.
Parent - - By IgorJorobus Date 2013-12-10 11:58
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.
Parent - - By jahmaican Date 2013-12-10 12:32
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.
Parent - - By IgorJorobus Date 2013-12-10 13:40
Understood. Thanks for the help, see you around guys!
Parent - - By lol_o2 Date 2013-12-10 14:42
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.
Parent - By IgorJorobus Date 2013-12-11 01:29
Okat that's a very good advertise, thank you lol_o2 !
Parent - - By RavensKrag Date 2013-12-20 03:43
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.
Parent - By IgorJorobus Date 2013-12-21 19:20
Thanks for the information RavensKrag, it's appreciated.
Up Topic Gosu / Gosu Exchange / A game with mouse input

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill