Game Key Events: Event or Method Overload?

Posted by Ell on Stack Overflow See other posts from Stack Overflow or by Ell
Published on 2010-05-02T12:23:59Z Indexed on 2010/05/02 12:27 UTC
Read the original article Hit count: 301

Filed under:
|
|
|
|

If you were going to develop a game in say, Ruby, and you were provided with a game framework, would you rather act on key up/down events by overloading a method on the main window like so:

class MyGameWindow < Framework::GameWindow
    def button_down(id)
        case id
            when UpArrow
                do_something
            when DownArrow
                do_something
        end
    end
end

Or have an event class with which you can make a method and assign a handle to it, like so:

class MyGameWindow < Framework::GameWindow
    def initialize
        key_down.add_handler(method(:do_something))
    end
    def do_something
        puts "blah blah"
    end
end

Please give your views, which do you think would be better in a game developement area, and thanks in advance, ell.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about event