Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Created September 19, 2011 23:25
Show Gist options
  • Save jwoertink/1227889 to your computer and use it in GitHub Desktop.
Save jwoertink/1227889 to your computer and use it in GitHub Desktop.
# Unnecessary code removed
require 'java'
java_import "com.jme3.app.SimpleApplication"
java_import "com.jme3.input.controls.ActionListener"
class HelloInput < SimpleApplication
def initKeys
input_manager.add_listener(action_listener, ["Pause"].to_java(:string))
end
private
def action_listener
ActionListener.new {
def on_action(name, key_pressed, time_per_frame)
@is_running = !@is_running if name.eql?("Pause") && !key_pressed
end
}
end
end
@jwoertink
Copy link
Author

Alternate version I've tried...

def action_listener 
  Class.new {
    include ActionListener
    def on_action(name, key_pressed, time_per_frame)
      if name.eql?("Pause") && !key_pressed
        @is_running = !@is_running
      end
    end
  }.new
end

@jwoertink
Copy link
Author

Alternate version #2

def action_listener
  ActionListener.impl {
    def on_action(name, key_pressed, time_per_frame)
      @is_running = !@is_running if name.eql?("Pause") && !key_pressed
    end
  }
end

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