Window and View#

arcade.close_window#

arcade.close_window() None[source]#

Closes the current window, and then runs garbage collection. The garbage collection is necessary to prevent crashing when opening/closing windows rapidly (usually during unit tests).

arcade.create_orthogonal_projection#

arcade.create_orthogonal_projection(left: float, right: float, bottom: float, top: float, near: float = 1, far: float = -1) Mat4[source]#

Creates an orthogonal projection matrix. Used internally with the OpenGL shaders. It creates the same matrix as the deprecated/removed glOrtho OpenGL function.

Parameters:
  • left (float) – The left of the near plane relative to the plane’s center.

  • right (float) – The right of the near plane relative to the plane’s center.

  • top (float) – The top of the near plane relative to the plane’s center.

  • bottom (float) – The bottom of the near plane relative to the plane’s center.

  • near (float) – The distance of the near plane from the camera’s origin. It is recommended that the near plane is set to 1.0 or above to avoid rendering issues at close range.

  • far (float) – The distance of the far plane from the camera’s origin.

Returns:

A projection matrix representing the specified orthogonal perspective.

Return type:

pyglet.math.Mat4

arcade.exit#

arcade.exit()[source]#

Exits the application.

arcade.finish_render#

arcade.finish_render()[source]#

Swap buffers and displays what has been drawn.

Warning

If you are extending the Window class, this function should not be called. The event loop will automatically swap the window framebuffer for you after on_draw.

arcade.get_display_size#

arcade.get_display_size(screen_id: int = 0) Tuple[int, int][source]#

Return the width and height of a monitor.

The size of the primary monitor is returned by default.

Parameters:

screen_id (int) – The screen number

Returns:

Tuple containing the width and height of the screen

Return type:

tuple

arcade.get_projection#

arcade.get_projection() Mat4[source]#

Returns the current projection matrix used by sprites and shapes in arcade.

This is a shortcut for `window.ctx.projection_2d_matrix.

Returns:

Projection matrix

Return type:

Mat4

arcade.get_scaling_factor#

arcade.get_scaling_factor(window: Window = None) float[source]#

Gets the scaling factor of the given Window. This is the ratio between the window and framebuffer size. If no window is supplied the currently active window will be used.

Parameters:

window (Window) – Handle to window we want to get scaling factor of.

Returns:

Scaling factor. E.g., 2.0 would indicate the framebuffer width and height being 2.0 times the window width and height. This means one “window pixel” is actual a 2 x 2 square of pixels in the framebuffer.

Return type:

float

arcade.get_viewport#

arcade.get_viewport() Tuple[float, float, float, float][source]#

Get the current viewport settings.

Returns:

Tuple of floats, with (left, right, bottom, top)

arcade.get_window#

arcade.get_window() Window[source]#

Return a handle to the current window.

Returns:

Handle to the current window.

arcade.pause#

arcade.pause(seconds: Number) None[source]#

Pause for the specified number of seconds. This is a convenience function that just calls time.sleep().

Warning

This is mostly used for unit tests and is not likely to be a good solution for pausing an application or game.

Parameters:

seconds (float) – Time interval to pause in seconds.

arcade.run#

arcade.run()[source]#

Run the main loop. After the window has been set up, and the event hooks are in place, this is usually one of the last commands on the main program. This is a blocking function starting pyglet’s event loop meaning it will start to dispatch events such as on_draw and on_update.

arcade.schedule#

arcade.schedule(function_pointer: Callable, interval: Number)[source]#

Schedule a function to be automatically called every interval seconds. The function/callable needs to take a delta time argument similar to on_update. This is a float representing the number of seconds since it was scheduled or called.

A function can be scheduled multiple times, but this is not recommended.

Warning

Scheduled functions should always be unscheduled using arcade.unschedule(). Having lingering scheduled functions will lead to crashes.

Example:

def some_action(delta_time):
    print(delta_time)

# Call the function every second
arcade.schedule(some_action, 1)
# Unschedule
Parameters:
  • function_pointer (Callable) – Pointer to the function to be called.

  • interval (Number) – Interval to call the function (float or integer)

arcade.set_background_color#

arcade.set_background_color(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]) None[source]#

Set the color arcade.Window.clear() will use when clearing the window. This only needs to be called when the background color changes.

Note

A shorter and faster way to set background color is using arcade.Window.background_color.

Examples:

# Use Arcade's built in color values
arcade.set_background_color(arcade.color.AMAZON)

# Specify RGB value directly (red)
arcade.set_background_color((255, 0, 0))
Parameters:

color (Color) – List of 3 or 4 values in RGB/RGBA format.

arcade.set_viewport#

arcade.set_viewport(left: float, right: float, bottom: float, top: float) None[source]#

This sets what coordinates the window will cover.

Tip

Beginners will want to use Camera. It provides easy to use support for common tasks such as screen shake and movement to a destination.

If you are making a game with complex control over the viewport, this function can help.

By default, the lower left coordinate will be (0, 0), the top y coordinate will be the height of the window in pixels, and the right x coordinate will be the width of the window in pixels.

Warning

Be careful of fractional or non-multiple values!

It is recommended to only set the viewport to integer values that line up with the pixels on the screen. Otherwise, tiled pixel art may not line up well during render, creating rectangle artifacts.

Note

Window.on_resize calls set_viewport by default. If you want to set your own custom viewport during the game, you may need to override the Window.on_resize method.

Note

For more advanced users

This functions sets the orthogonal projection used by shapes and sprites. It also updates the viewport to match the current screen resolution. window.ctx.projection_2d (projection_2d()) and window.ctx.viewport (viewport()) can be used to set viewport and projection separately.

Parameters:
  • left (Number) – Left-most (smallest) x value.

  • right (Number) – Right-most (largest) x value.

  • bottom (Number) – Bottom (smallest) y value.

  • top (Number) – Top (largest) y value.

arcade.set_window#

arcade.set_window(window: Window) None[source]#

Set a handle to the current window.

Parameters:

window (Window) – Handle to the current window.

arcade.start_render#

arcade.start_render() None[source]#

Clears the window.

More practical alternatives to this function is arcade.Window.clear() or arcade.View.clear().

arcade.unschedule#

arcade.unschedule(function_pointer: Callable)[source]#

Unschedule a function being automatically called.

Example:

def some_action(delta_time):
    print(delta_time)

arcade.schedule(some_action, 1)
arcade.unschedule(some_action)
Parameters:

function_pointer (Callable) – Pointer to the function to be unscheduled.

arcade.NoOpenGLException#

class arcade.NoOpenGLException[source]#

Exception when we can’t get an OpenGL 3.3+ context

arcade.View#

class arcade.View(window: Optional[Window] = None)[source]#

Support different views/screens in a window.

add_section(section, at_index: Optional[int] = None) None[source]#

Adds a section to the view Section Manager.

Parameters:
  • section – the section to add to this section manager

  • at_index – inserts the section at that index. If None at the end

clear(color: Optional[Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]] = None, normalized: bool = False, viewport: Optional[Tuple[int, int, int, int]] = None)[source]#

Clears the View’s Window with the configured background color set through arcade.Window.background_color.

Parameters:
  • color (Color) – Optional color overriding the current background color

  • normalized (bool) – If the color format is normalized (0.0 -> 1.0) or byte values

  • viewport (Tuple[int, int, int, int]) – The viewport range to clear

property has_sections: bool#

Return if the View has sections

on_draw()[source]#

Called when this view should draw

on_hide_view()[source]#

Called once when this view is hidden.

on_key_press(symbol: int, modifiers: int)[source]#

Override this function to add key press functionality.

Parameters:
  • symbol (int) – Key that was hit

  • modifiers (int) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_key_release(_symbol: int, _modifiers: int)[source]#

Override this function to add key release functionality.

Parameters:
  • _symbol (int) – Key that was hit

  • _modifiers (int) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_drag(x: int, y: int, dx: int, dy: int, _buttons: int, _modifiers: int)[source]#

Override this function to add mouse button functionality.

Parameters:
  • x (int) – x position of mouse

  • y (int) – y position of mouse

  • dx (int) – Change in x since the last time this method was called

  • dy (int) – Change in y since the last time this method was called

  • _buttons (int) – Which button is pressed

  • _modifiers (int) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_enter(x: int, y: int)[source]#

Called when the mouse was moved into the window. This event will not be triggered if the mouse is currently being dragged.

Parameters:
  • x (int) – x position of mouse

  • y (int) – y position of mouse

on_mouse_leave(x: int, y: int)[source]#

Called when the mouse was moved outside of the window. This event will not be triggered if the mouse is currently being dragged. Note that the coordinates of the mouse pointer will be outside of the window rectangle.

Parameters:
  • x (int) – x position of mouse

  • y (int) – y position of mouse

on_mouse_motion(x: int, y: int, dx: int, dy: int)[source]#

Override this function to add mouse functionality.

Parameters:
  • x (int) – x position of mouse

  • y (int) – y position of mouse

  • dx (int) – Change in x since the last time this method was called

  • dy (int) – Change in y since the last time this method was called

on_mouse_press(x: int, y: int, button: int, modifiers: int)[source]#

Override this function to add mouse button functionality.

Parameters:
  • x (int) – x position of the mouse

  • y (int) – y position of the mouse

  • button (int) – What button was hit. One of: arcade.MOUSE_BUTTON_LEFT, arcade.MOUSE_BUTTON_RIGHT, arcade.MOUSE_BUTTON_MIDDLE

  • modifiers (int) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_release(x: int, y: int, button: int, modifiers: int)[source]#

Override this function to add mouse button functionality.

Parameters:
  • x (int) – x position of mouse

  • y (int) – y position of mouse

  • button (int) – What button was hit. One of: arcade.MOUSE_BUTTON_LEFT, arcade.MOUSE_BUTTON_RIGHT, arcade.MOUSE_BUTTON_MIDDLE

  • modifiers (int) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_scroll(x: int, y: int, scroll_x: int, scroll_y: int)[source]#

User moves the scroll wheel.

Parameters:
  • x (int) – x position of mouse

  • y (int) – y position of mouse

  • scroll_x (int) – ammout of x pixels scrolled since last call

  • scroll_y (int) – ammout of y pixels scrolled since last call

on_resize(width: int, height: int)[source]#

Called when the window is resized while this view is active. on_resize() is also called separately. By default this method does nothing and can be overridden to handle resize logic.

on_show()[source]#

Deprecated. Use on_show_view() instead.

on_show_view()[source]#

Called once when the view is shown.

See also

on_hide_view()

on_update(delta_time: float)[source]#

To be overridden

arcade.Window#

class arcade.Window(width: int = 800, height: int = 600, title: Optional[str] = 'Arcade Window', fullscreen: bool = False, resizable: bool = False, update_rate: float = 0.016666666666666666, antialiasing: bool = True, gl_version: Tuple[int, int] = (3, 3), screen: Optional[Screen] = None, style: Optional[str] = None, visible: bool = True, vsync: bool = False, gc_mode: str = 'context_gc', center_window: bool = False, samples: int = 4, enable_polling: bool = True, gl_api: str = 'gl', draw_rate: float = 0.016666666666666666)[source]#

The Window class forms the basis of most advanced games that use Arcade. It represents a window on the screen, and manages events.

Parameters:
  • width (int) – Window width

  • height (int) – Window height

  • title (str) – Title (appears in title bar)

  • fullscreen (bool) – Should this be full screen?

  • resizable (bool) – Can the user resize the window?

  • update_rate (float) – How frequently to run the on_update event.

  • draw_rate (float) – How frequently to run the on_draw event. (this is the FPS limit)

  • antialiasing (bool) – Should OpenGL’s anti-aliasing be enabled?

  • gl_version (Tuple[int,int]) – What OpenGL version to request. This is (3, 3) by default and can be overridden when using more advanced OpenGL features.

  • visible (bool) – Should the window be visible immediately

  • vsync (bool) – Wait for vertical screen refresh before swapping buffer This can make animations and movement look smoother.

  • gc_mode (bool) – Decides how OpenGL objects should be garbage collected (“context_gc” (default) or “auto”)

  • center_window (bool) – If true, will center the window.

  • samples (bool) – Number of samples used in antialiasing (default 4). Usually this is 2, 4, 8 or 16.

  • enable_polling (bool) – Enabled input polling capability. This makes the keyboard and mouse attributes available for use.

activate()[source]#

Activate this window.

property background_color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]#

Get or set the background color for this window. This affects what color the window will contain when clear() is called.

Examples:

# Use Arcade's built in color values
window.background_color = arcade.color.AMAZON

# Specify RGB value directly (red)
window.background_color = 255, 0, 0

If the background color is an RGB value instead of RGBA we assume alpha value 255.

Type:

Color

center_window()[source]#

Center the window on the screen.

clear(color: Optional[Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]] = None, normalized: bool = False, viewport: Optional[Tuple[int, int, int, int]] = None)[source]#

Clears the window with the configured background color set through arcade.Window.background_color.

Parameters:
  • color (Color) – Optional color overriding the current background color

  • normalized (bool) – If the color format is normalized (0.0 -> 1.0) or byte values

  • viewport (Tuple[int, int, int, int]) – The viewport range to clear

close()[source]#

Close the Window.

property ctx: ArcadeContext#

The OpenGL context for this window.

Type:

arcade.ArcadeContext

property current_view: Optional[View]#

This property returns the current view being shown. To set a different view, call the arcade.Window.show_view() method.

Return type:

arcade.View

dispatch_events()[source]#

Dispatch events

flip()[source]#

Window framebuffers normally have a back and front buffer. This method makes the back buffer visible and hides the front buffer. A frame is rendered into the back buffer, so this method displays the frame we currently worked on.

This method also garbage collect OpenGL resources before swapping the buffers.

get_location() Tuple[int, int][source]#

Return the X/Y coordinates of the window

Returns:

x, y of window location

get_size() Tuple[int, int][source]#

Get the size of the window.

Returns:

(width, height)

get_system_mouse_cursor(name)[source]#

Get the system mouse cursor

get_viewport() Tuple[float, float, float, float][source]#

Get the viewport. (What coordinates we can see.)

headless#

bool: If this is a headless window

hide_view()[source]#

Hide the currently active view (if any) returning us back to on_draw and on_update functions in the window.

This is not necessary to call if you are switching views. Simply call show_view again.

maximize()[source]#

Maximize the window.

minimize()[source]#

Minimize the window.

on_draw()[source]#

Override this function to add your custom drawing code.

on_key_press(symbol: int, modifiers: int)[source]#

Called once when a key gets pushed down.

Override this function to add key press functionality.

Tip

If you want the length of key presses to affect gameplay, you also need to override on_key_release().

Parameters:
  • symbol (int) – Key that was just pushed down

  • modifiers (int) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_key_release(symbol: int, modifiers: int)[source]#

Called once when a key gets released.

Override this function to add key release functionality.

Situations that require handling key releases include:

  • Rythm games where a note must be held for a certain amount of time

  • ‘Charging up’ actions that change strength depending on how long a key was pressed

  • Showing which keys are currently pressed down

Parameters:
  • symbol (int) – Key that was just released

  • modifiers (int) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_drag(x: int, y: int, dx: int, dy: int, buttons: int, modifiers: int)[source]#

Called repeatedly while the mouse moves with a button down.

Override this function to handle dragging.

Parameters:
  • x (int) – x position of mouse

  • y (int) – y position of mouse

  • dx (int) – Change in x since the last time this method was called

  • dy (int) – Change in y since the last time this method was called

  • buttons (int) – Which button is pressed

  • modifiers (int) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_enter(x: int, y: int)[source]#

Called once whenever the mouse enters the window area on screen.

This event will not be triggered if the mouse is currently being dragged.

Parameters:
on_mouse_leave(x: int, y: int)[source]#

Called once whenever the mouse leaves the window area on screen.

This event will not be triggered if the mouse is currently being dragged. Note that the coordinates of the mouse pointer will be outside of the window rectangle.

Parameters:
on_mouse_motion(x: int, y: int, dx: int, dy: int)[source]#

Called repeatedly while the mouse is moving over the window.

Override this function to respond to changes in mouse position.

Parameters:
  • x (int) – x position of mouse within the window in pixels

  • y (int) – y position of mouse within the window in pixels

  • dx (int) – Change in x since the last time this method was called

  • dy (int) – Change in y since the last time this method was called

on_mouse_press(x: int, y: int, button: int, modifiers: int)[source]#

Called once whenever a mouse button gets pressed down.

Override this function to handle mouse clicks. For an example of how to do this, see arcade’s built-in aiming and shooting bullets demo.

Parameters:
  • x (int) – x position of the mouse

  • y (int) – y position of the mouse

  • button (int) –

    What button was pressed. This will always be one of the following:

    • arcade.MOUSE_BUTTON_LEFT

    • arcade.MOUSE_BUTTON_RIGHT

    • arcade.MOUSE_BUTTON_MIDDLE

  • modifiers (int) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_release(x: int, y: int, button: int, modifiers: int)[source]#

Called once whenever a mouse button gets released.

Override this function to respond to mouse button releases. This may be useful when you want to use the duration of a mouse click to affect gameplay.

Parameters:
  • x (int) – x position of mouse

  • y (int) – y position of mouse

  • button (int) – What button was hit. One of: arcade.MOUSE_BUTTON_LEFT, arcade.MOUSE_BUTTON_RIGHT, arcade.MOUSE_BUTTON_MIDDLE

  • modifiers (int) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_scroll(x: int, y: int, scroll_x: int, scroll_y: int)[source]#

Called repeatedly while a mouse scroll wheel moves.

Override this function to respond to scroll events. The scroll arguments may be positive or negative to indicate direction, but the units are unstandardized. How many scroll steps you recieve may vary wildly between computers depending a number of factors, including system settings and the input devices used (i.e. mouse scrollwheel, touchpad, etc).

Warning

Not all users can scroll easily!

Only some input devices support horizontal scrolling. Standard vertical scrolling is common, but some laptop touchpads are hard to use.

This means you should be careful about how you use scrolling. Consider making it optional to maximize the number of people who can play your game!

Parameters:
  • x (int) – x position of mouse

  • y (int) – y position of mouse

  • scroll_x (int) – number of steps scrolled horizontally since the last call of this function

  • scroll_y (int) – number of steps scrolled vertically since the last call of this function

on_resize(width: float, height: float)[source]#

Override this function to add custom code to be called any time the window is resized. The main responsibility of this method is updating the projection and the viewport.

If you are not changing the default behavior when overriding, make sure you call the parent’s on_resize first:

def on_resize(self, width: int, height: int):
    super().on_resize(width, height)
    # Add extra resize logic here
Parameters:
  • width (int) – New width

  • height (int) – New height

on_update(delta_time: float)[source]#

Move everything. Perform collision checks. Do all the game logic here.

Parameters:

delta_time (float) – Time interval since the last time the function was called.

run()[source]#

Run the main loop. After the window has been set up, and the event hooks are in place, this is usually one of the last commands on the main program. This is a blocking function starting pyglet’s event loop meaning it will start to dispatch events such as on_draw and on_update.

set_caption(caption)[source]#

Set the caption for the window.

set_draw_rate(rate: float)[source]#

Set how often the on_draw function should be run. For example, set.set_draw_rate(1 / 60) will set the draw rate to 60 frames per second.

set_exclusive_keyboard(exclusive=True)[source]#

Capture all keyboard input.

set_exclusive_mouse(exclusive=True)[source]#

Capture the mouse.

set_fullscreen(fullscreen: bool = True, screen: Optional[Window] = None, mode: Optional[ScreenMode] = None, width: Optional[float] = None, height: Optional[float] = None)[source]#

Set if we are full screen or not.

Parameters:
  • fullscreen (bool) –

  • screen – Which screen should we display on? See get_screens()

  • mode (pyglet.canvas.ScreenMode) – The screen will be switched to the given mode. The mode must have been obtained by enumerating Screen.get_modes. If None, an appropriate mode will be selected from the given width and height.

  • width (int) –

  • height (int) –

set_location(x, y)[source]#

Set location of the window.

set_max_size(width: int, height: int)[source]#

Wrap the Pyglet window call to set maximum size

Parameters:
  • width (int) – width in pixels.

  • height (int) – height in pixels.

Raises ValueError:

set_maximum_size(width, height)[source]#

Set largest window size.

set_min_size(width: int, height: int)[source]#

Wrap the Pyglet window call to set minimum size

Parameters:
  • width (float) – width in pixels.

  • height (float) – height in pixels.

set_minimum_size(width: int, height: int)[source]#

Set smallest window size.

set_mouse_platform_visible(platform_visible=None)[source]#

Warning

You are probably looking for set_mouse_visible()!

This method was implemented to prevent PyCharm from displaying linter warnings. Most users will never need to set platform-specific visibility as the defaults from pyglet will usually handle their needs automatically.

For more information on what this means, see the documentation for pyglet.window.Window.set_mouse_platform_visible().

set_mouse_visible(visible: bool = True)[source]#

Set whether to show the system’s cursor while over the window

By default, the system mouse cursor is visible whenever the mouse is over the window. To hide the cursor, pass False to this function. Pass True to make the cursor visible again.

The window will continue receiving mouse events while the cursor is hidden, including movements and clicks. This means that functions like on_mouse_motion() and t’on_mouse_press() will continue to work normally.

You can use this behavior to visually replace the system mouse cursor with whatever you want. One example is a game character that is always at the most recent mouse position in the window.

Note

Advanced users can try using system cursor state icons

It may be possible to use system icons representing cursor interaction states such as hourglasses or resize arrows by using features arcade.Window inherits from the underlying pyglet window class. See the pyglet overview on cursors for more information.

Parameters:

visible (bool) – Whether to hide the system mouse cursor

set_size(width: int, height: int)[source]#

Ignore the resizable flag and set the size

Parameters:
  • width (int) –

  • height (int) –

set_update_rate(rate: float)[source]#

Set how often the on_update function should be dispatched. For example, self.set_update_rate(1 / 60) will set the update rate to 60 times per second.

Parameters:

rate (float) – Update frequency in seconds

set_viewport(left: float, right: float, bottom: float, top: float)[source]#

Set the viewport. (What coordinates we can see. Used to scale and/or scroll the screen).

See arcade.set_viewport() for more detailed information.

Parameters:
  • left (Number) –

  • right (Number) –

  • bottom (Number) –

  • top (Number) –

set_visible(visible: bool = True)[source]#

Set if the window is visible or not. Normally, a program’s window is visible.

Parameters:

visible (bool) –

set_vsync(vsync: bool)[source]#

Set if we sync our draws to the monitors vertical sync rate.

show_view(new_view: View)[source]#

Select the view to show in the next frame. This is not a blocking call showing the view. Your code will continue to run after this call and the view will appear in the next dispatch of on_update/on_draw`.

Calling this function is the same as setting the arcade.Window.current_view attribute.

Parameters:

new_view (View) – View to show

switch_to()[source]#

Switch the this window.

test(frames: int = 10)[source]#

Used by unit test cases. Runs the event loop a few times and stops.

Parameters:

frames (int) –

use()[source]#

Bind the window’s framebuffer for rendering commands

arcade.get_screens#

arcade.get_screens()[source]#

Return a list of screens. So for a two-monitor setup, this should return a list of two screens. Can be used with arcade.Window to select which window we full-screen on.

Returns:

List of screens, one for each monitor.

Return type:

List

arcade.open_window#

arcade.open_window(width: int, height: int, window_title: Optional[str] = None, resizable: bool = False, antialiasing: bool = True) Window[source]#

This function opens a window. For ease-of-use we assume there will only be one window, and the programmer does not need to keep a handle to the window. This isn’t the best architecture, because the window handle is stored in a global, but it makes things easier for programmers if they don’t have to track a window pointer.

Parameters:
  • width (Number) – Width of the window.

  • height (Number) – Height of the window.

  • window_title (str) – Title of the window.

  • resizable (bool) – Whether the user can resize the window.

  • antialiasing (bool) – Smooth the graphics?

Returns:

Handle to window

Return type:

Window

arcade.Section#

class arcade.Section(left: int, bottom: int, width: int, height: int, *, name: Optional[str] = None, accept_keyboard_events: Union[bool, Iterable] = True, prevent_dispatch: Optional[Iterable] = None, prevent_dispatch_view: Optional[Iterable] = None, local_mouse_coordinates: bool = False, enabled: bool = True, modal: bool = False)[source]#

A Section represents a rectangular portion of the viewport Events are dispatched to the section based on it’s position on the screen.

property bottom: int#

The bottom edge of this section

property enabled: bool#

enables or disables this section

get_xy_screen_relative(section_x: int, section_y: int)[source]#

Returns screen coordinates from section coordinates

get_xy_section_relative(screen_x: int, screen_y: int)[source]#

returns section coordinates from screen coordinates

property height: int#

The height of this section

property left: int#

Left edge of this section

property modal: bool#

Returns the modal state (Prevent the following sections from receiving input events and updating)

mouse_is_on_top(x: int, y: int) bool[source]#

Check if the current mouse position is on top of this section

overlaps_with(section) bool[source]#

Checks if this section overlaps with another section

property right: int#

Right edge of this section

property section_manager: Optional[SectionManager]#

Returns the section manager

property top: int#

Top edge of this section

property view#

The view this section is set on

property width: int#

The width of this section

property window#

The view window

arcade.SectionManager#

class arcade.SectionManager(view)[source]#

This manages the different Sections a View has. Actions such as dispatching the events to the correct Section, draw order, etc.

add_section(section: Section, at_index: Optional[int] = None) None[source]#

Adds a section to this Section Manager :param section: the section to add to this section manager :param at_index: inserts the section at that index. If None at the end

clear_sections()[source]#

Removes all sections

disable() None[source]#

Disable all sections

disable_all_keyboard_events() None[source]#

Removes the keyboard events handling from all sections

dispatch_keyboard_event(event, *args, **kwargs) Optional[bool][source]#

Generic method to dispatch keyboard events to the correct sections

dispatch_mouse_event(event: str, x: int, y: int, *args, **kwargs) Optional[bool][source]#

Generic method to dispatch mouse events to the correct Section

enable() None[source]#

Enables all section

get_section(x: int, y: int) Optional[Section][source]#

Returns the first section based on x,y position

get_section_by_name(name: str) Optional[Section][source]#

Returns the first section with the given name

property has_sections: bool#

Returns true if sections are available

on_draw()[source]#

Called on each event loop. First dispatch the view event, then the section ones. It automatically calls camera.use() for each section that has a camera and resets the camera effects by calling the default SectionManager camera afterwards if needed.

on_mouse_drag(x: int, y: int, *args, **kwargs) Optional[bool][source]#
This method dispatches the on_mouse_drag and also calculates

if on_mouse_enter/leave should be fired

on_mouse_motion(x: int, y: int, *args, **kwargs) Optional[bool][source]#
This method dispatches the on_mouse_motion and also calculates

if on_mouse_enter/leave should be fired

on_resize(width: int, height: int)[source]#

Called when the window is resized. First dispatch the view event, then the section ones.

on_update(delta_time: float)[source]#

Called on each event loop. First dispatch the view event, then the section ones.

remove_section(section: Section) None[source]#

Removes a section from this section manager