Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / How can I use button_down? in a class?
- - By h4y4shi Date 2012-02-27 06:41
I have a class and I want it to use the button_down? method, but whenever I try to use it in a class it says the method is unidentified. How do I pass the method to a class from the Window?
The only time I ever seeing button_down? being used is inside the Gosu Window. I want to know if there is a way to use it with a class.

Here is a pastie of the non-functioning class http://pastie.org/3469485

Here is my error
C:/.../tileclasses.rb:72:in draw': undefined method button_down?' for #<GrassTile:0x2c28b10> (NoMethodError)
        from main.rb:56:in block in draw'
        from main.rb:56:in
each'
        from main.rb:56:in draw'
        from main.rb:59:in
<main>'
Parent - By Spooner Date 2012-02-27 14:17
button_down? is a method on Gosu::Window. You'd use

def initialize(window)
    @x = x
    @y = y
    @width = width
    @height = height
    @image = Gosu::Image.new(window, "media/grass.png", false)
    @window = window
  end
  def draw(mouse_x, mouse_y)
    if @window.button_down? ...


However, it is more common to set $window = self in the Gosu::Window#initialize, since it is used all through a Gosu game. Stylistically, however, you should be doing the processing in #update, not #draw.
Up Topic Gosu / Gosu Exchange / How can I use button_down? in a class?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill