1 = EventManager Class Reference =
4 _Italics_ means private (in the sense that they shouldn't be set manually).
7 `---------------------`--------------------
9 -------------------------------------------
10 *keyboard* keyboard event table
11 keyboard.pressed keyboard pressed events
12 keyboard.released keyboard release events
13 *mouse* mouse event table
14 mouse.motion mouse motion event
15 mouse.pressed mouse pressed events
16 mouse.released mouse released events
17 *joystick* joystick event table
18 joystick.axis_motion joystick axis motion events
19 joystick.ball_motion joystick ball motion events
20 joystick.hat_motion joystick hat motion events
21 joystick.pressed joystick button pressed events
22 joystick.released joystick button released events
24 _state_ state variable
29 -------------------------------------------
33 `--------------`------------------------
35 ----------------------------------------
37 gather_events() processes all pending events
38 ----------------------------------------
40 == Event Function Prototypes ==
42 `---------------------`-------------------
44 ------------------------------------------
45 mouse.motion function(x, y, xrel, yrel)
46 mouse.pressed function(x, y)
47 mouse.released function(x, y)
48 joystick.axis_motion function(axis, axis_value)
49 joystick.ball_motion function(ball, xrel, yrel)
50 joystick.hat_motion function(hat, hat_value)
51 joystick.pressed function(button)
52 joystick.released function(button)
53 ------------------------------------------
56 Joysticks and joystick buttons start numbering at 1, not 0.
61 source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62 --create a new EventManager
63 evman = EventManager:new()
65 --add an event to exit when ESC is pressed
66 -- assumes main loop is controlled by variable "done"
67 evman.keyboard.pressed[Keys.ESCAPE] = function() done = true end
69 --events to control a player object's movement
70 evman.keyboard.pressed[Keys.UP] = function() player.y_vel = -1 end
71 evman.keyboard.pressed[Keys.DOWN] = function() player.y_vel = 1 end
72 evman.keyboard.pressed[Keys.LEFT] = function() player.x_vel = -1 end
73 evman.keyboard.pressed[Keys.RIGHT] = function() player.x_vel = 1 end
75 evman.keyboard.released[Keys.UP] = function() player.y_vel = 0 end
76 evman.keyboard.released[Keys.DOWN] = function() player.y_vel = 0 end
77 evman.keyboard.released[Keys.LEFT] = function() player.x_vel = 0 end
78 evman.keyboard.released[Keys.RIGHT] = function() player.x_vel = 0 end
80 --EventManager for a fictional menu object
81 menu_evman = EventManager:new()
82 menu_evman.keyboard.pressed[Keys.UP] = function() menu.next_item() end
83 menu_evman.keyboard.pressed[Keys.DOWN] = function() menu.prev_item() end
84 menu_evman.keyboard.pressed[Keys.RETURN] = function() menu.execute() end
86 --Controlling a player with the mouse
87 evman.mouse.motion = function(x, y) player.x = x player.y = y end
88 evman.mouse.pressed[MouseButton.BUTTON_LEFT] = function() player.firing = true end
89 evman.mouse.released[MouseButton.BUTTON_LEFT] = function() player.firing = false end
92 source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~