Fixed some little errors with the drawing functions.
[luagame.git] / doc / class_eventmanager.txt
blob91f8674a72d6d6fe40e93884ce8d874e9f87d996
1 = EventManager Class Reference =
3 == Attributes ==
4 _Italics_ means private (in the sense that they shouldn't be set manually).
6 [grid="all"]
7 `---------------------`--------------------
8 Attribute              Description
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
23 quit                   quit event
24 _type_                 state variable
25 _state_                state variable
26 _arg1_                 state variable
27 _arg2_                 state variable
28 _arg3_                 state variable
29 _arg4_                 state variable
30 -------------------------------------------
32 == Methods == 
33 [grid="all"]
34 `--------------`------------------------
35 Method           Description
36 ----------------------------------------
37 new(o)           constructor
38 gather_events()  processes all pending events
39 ----------------------------------------
41 == Event Function Prototypes ==
42 [grid="all"]
43 `---------------------`-------------------
44 Event                  Prototype
45 ------------------------------------------
46 mouse.motion           function(x, y, xrel, yrel)
47 mouse.pressed          function(x, y)
48 mouse.released         function(x, y)
49 joystick.axis_motion   function(axis, axis_value)
50 joystick.ball_motion   function(ball, xrel, yrel)
51 joystick.hat_motion    function(hat, hat_value)
52 joystick.pressed       function(button)
53 joystick.released      function(button)
54 quit                   function()
55 ------------------------------------------
57 == Notes ==
58 Joysticks and joystick buttons start numbering at 1, not 0.
60 == Usage ==
62 [lua]
63 source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64 --create a new EventManager
65 evman = EventManager:new()
67 --add an event to exit when ESC is pressed
68 -- assumes main loop is controlled by variable "done"
69 evman.keyboard.pressed[Keys.ESCAPE] = function() done = true end
71 --events to control a player object's movement
72 evman.keyboard.pressed[Keys.UP] = function() player.y_vel = -1 end
73 evman.keyboard.pressed[Keys.DOWN] = function() player.y_vel = 1 end
74 evman.keyboard.pressed[Keys.LEFT] = function() player.x_vel = -1 end
75 evman.keyboard.pressed[Keys.RIGHT] = function() player.x_vel = 1 end
77 evman.keyboard.released[Keys.UP] = function() player.y_vel = 0 end
78 evman.keyboard.released[Keys.DOWN] = function() player.y_vel = 0 end
79 evman.keyboard.released[Keys.LEFT] = function() player.x_vel = 0 end
80 evman.keyboard.released[Keys.RIGHT] = function() player.x_vel = 0 end
82 --EventManager for a fictional menu object
83 menu_evman = EventManager:new()
84 menu_evman.keyboard.pressed[Keys.UP] = function() menu.next_item() end
85 menu_evman.keyboard.pressed[Keys.DOWN] = function() menu.prev_item() end
86 menu_evman.keyboard.pressed[Keys.RETURN] = function() menu.execute() end
88 --Controlling a player with the mouse
89 -- assume there exists a player:set_pos(x,y) method
91 --wrapper function for player:set_pos(x,y)
92 function move_player(x,y)
93   player:set_pos(x,y)
94 end
96 evman.mouse.motion = move_player(x,y)
97 evman.mouse.pressed[MouseButton.BUTTON_LEFT] = function() player.firing = true end
98 evman.mouse.released[MouseButton.BUTTON_LEFT] = function() player.firing = false end
100 --quitting (assumes main loop is controlled by done variable)
101 evman.quit = function() done = true end
103 source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~