sdl2.ext.manager - Basic scene manager.¶
Basic scene manager.
-
class
sdl2.ext.manager.Manager(width=None, height=None, tile_size=None, limit_fps=None, window_color=None, resources_path=None)¶ Bases:
objectManage scenes and the main game loop.
At each loop the events are passed down to the active scene and it’s update method is called.
-
__init__(width=None, height=None, tile_size=None, limit_fps=None, window_color=None, resources_path=None)¶ Initialization.
Parameters: - width (int) – the width of the screen in pixels. default to sdl2.cfg[MANAGER][SCREEN_WIDTH] or, if unavailable, the desktop width.
- height (int) – the height of the screen in pixels. default to sdl2.cfg[MANAGER][SCREEN_HEIGHT] or, if unavailable, the desktop height.
- tile_size (int) – size of a (square) tile’s side in pixels.
- limit_fps (int) – maximum frames per second that should be drawn.
- window_color (4-tuple) – the window’s background color, as a tuple of 4 integers representing Red, Greehn, Blue and Alpha values (0-255).
- Usage:
- m = Manager() # start with default parameters m.set_scene(SceneBase) # set a scene. This is a blank base scene m.execute() # call the main loop
-
draw_fps()¶ Draw the fps display.
-
on_event()¶ Handle the events and pass them to the active scene.
-
on_update()¶ Update the active scene.
-
present()¶ Flip the GPU buffer.
-
run()¶ Main loop handling events and updates.
-
-
class
sdl2.ext.manager.KeyboardStateController¶ Bases:
objectA class that keeps track of keyboard modifiers and locks.
-
__init__()¶ Initialization.
-
alt¶ ...
-
combine(alt=False, ctrl=False, shift=False)¶ ...
-
ctrl¶ ...
-
process(event)¶ Process the current event and update the keyboard state.
-
shift¶ ...
-
-
class
sdl2.ext.manager.SceneBase(**kwargs)¶ Bases:
objectBasic scene of the game.
New Scenes should be subclasses of SceneBase.
-
__init__(**kwargs)¶ Initialization.
-
factory¶ Reference to sdl2.ext.SpriteFactory instance.
Returns: Manager.factory
-
height¶ Main window height.
Returns: Manager.height
-
kb_state¶ Reference to KeyboardStateController instance.
Returns: Manager.kb_state
-
on_key_press(event, sym, mod)¶ Called on keyboard input, when a key is held down.
Parameters: - event (sdl2.events.SDL_Event) – The base event, as passed by sdl2 Unless specifically needed, sym and mod should be used instead.
- sym (int) – Integer representing code of the key pressed. For
printable keys
chr(key)should return the corresponding character. - mod (KeyboardStateController) – the keyboard state for modifiers and locks. See :class:KeyboardStateController
-
on_key_release(event, sym, mod)¶ Called on keyboard input, when a key is released.
By default if the Escape key is pressed the manager quits. If that behaviour is desired you can call
super().on_key_release( event, sym, mod)on a child class.Parameters: - event (sdl2.events.SDL_Event) – The base event, as passed by sdl2 The other arguments should be used for a higher level interaction, unless specifically needed.
- sym (int) – Integer representing code of the key pressed. For
printable keys
chr(key)should return the corresponding character. - mod (KeyboardStateController) – the keyboard state for modifiers and locks. See :class:KeyboardStateController
-
on_mouse_drag(event, x, y, dx, dy, button)¶ Called when mouse buttons are pressed and the mouse is dragged.
Parameters: - event (sdl2.events.SDL_Event) – The base event, as passed by sdl2 The other arguments should be used for a higher level interaction, unless specifically needed.
- x (int) – horizontal coordinate, relative to window.
- y (int) – vertical coordinate, relative to window.
- dx (int) – relative motion in the horizontal direction
- dy (int) – relative motion in the vertical direction
- button (str, "RIGHT"|"MIDDLE"|"LEFT") – string representing the button pressed.
-
on_mouse_motion(event, x, y, dx, dy)¶ Called when the mouse is moved.
Parameters: - event (sdl2.events.SDL_Event) – The base event, as passed by sdl2 The other arguments should be used for a higher level interaction, unless specifically needed.
- x (int) – horizontal coordinate, relative to window.
- y (int) – vertical coordinate, relative to window.
- dx (int) – relative motion in the horizontal direction
- dy (int) – relative motion in the vertical direction
-
on_mouse_press(event, x, y, button, double)¶ Called when mouse buttons are pressed.
Parameters: - event (sdl2.events.SDL_Event) – The base event, as passed by sdl2 The other arguments should be used for a higher level interaction, unless specifically needed.
- x (int) – horizontal coordinate, relative to window.
- y (int) – vertical coordinate, relative to window.
- button (str, "RIGHT"|"MIDDLE"|"LEFT") – string representing the button pressed.
- double (bool, True|False) – boolean indicating if the click was a double click.
-
on_mouse_scroll(event, offset_x, offset_y)¶ Called when the mouse wheel is scrolled.
Parameters: - event (sdl2.events.SDL_Event) – The base event, as passed by sdl2 The other arguments should be used for a higher level interaction, unless specifically needed.
- offset_x (int) – the amount scrolled horizontally, positive to the right and negative to the left.
- offset_y (int) – the amount scrolled vertically, positive away from the user and negative toward the user.
-
on_update()¶ Graphical logic.
-
quit()¶ Stop the manager main loop.
-
renderer¶ Reference to sdl2.ext.Renderer instance.
Returns: Manager.renderer
-
resources¶ Reference to sdl2.ext.Resources instance.
Returns: Manager.resources
-
sdlrenderer¶ Reference to sdl2.SDL_Renderer instance.
Returns: Manager.renderer.sdlrenderer
-
spriterenderer¶ Reference to sdl2.ext.TextureSpriteRenderSystem instance.
Returns: Manager.spriterenderer
-
width¶ Main window width.
Returns: Manager.height
-