I’m using JRuby with the libGDX framework, and I’ve gotten stuck trying
to setup some InputListeners that worked just fine when I was using
Java.
In Java, the process looks like this:
actor.addListener(new InputListener() {
public boolean touchDown (
InputEvent event, float x, float y, int pointer, int button)
{
System.out.println(“working”);
});
where the touchDown method is overidden as it is instantiated.
In Ruby, I’ve tried to use:
listener = InputListener.new
def listener.touchDown(event, x, y, pointer, button)
puts 'working'
end
@inv_button.add_listener(listener)
and all of its variants like class << listener def…end, and I’ve got
nothing. I have got it to respond using:
@inv_button.add_listener(
Class.new(InputListener) do
def touchDown(event, x, y, pointer, button)
puts 'working'
end
end.new
end
But the problem is that I’m now stuck in the scope of the InputListener
class when redefining touchDown so I can’t use it to setup the listener
as is intended. I don’t understand why this isn’t a problem with the
Java method. If I could pass something along to the new class in a proc
that would work, but I can’t figure out how to do that.
Any suggestions to try a completely different method are appreciated as
well.