Skip to content

Instantly share code, notes, and snippets.

@RyanScottLewis
Created September 22, 2013 05:21
Show Gist options
  • Save RyanScottLewis/6656957 to your computer and use it in GitHub Desktop.
Save RyanScottLewis/6656957 to your computer and use it in GitHub Desktop.
startGameButton.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
game.setScreen(new GameScreen(game));
return true;
}
});
@LeifW
Copy link

LeifW commented Sep 22, 2013

If InputListener is a Java Interface, JRuby has a feature where you can use a Ruby block for that, documented here:
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#closure-conversion

So in JRuby, this code might look like:

startGameButton.addListener {|event, x, y, pointer, button|
  game.setScreen( GameScreen.new(game) )
  true
}

Make sense?

It also lets you use snake_case instead of camelCase for those identifiers if you wish for things to look more ruby-like, and also has sugar for getters and setters. So I imaging you could write game.screen = GameScreen.new(game) instead of game.setScreen( GameScreen.new(game) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment