Window and View
Contents
arcade.close_window
arcade.create_orthogonal_projection
- arcade.create_orthogonal_projection(left, right, bottom, top, near=1, far=- 1) pyglet.math.Mat4 [source]
Creates an orthogonal projection matrix. Used internally with the OpenGL shaders.
- 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
Mat4
arcade.exit
arcade.finish_render
arcade.get_display_size
arcade.get_projection
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
arcade.get_viewport
arcade.get_window
arcade.pause
- arcade.pause(seconds: numbers.Number) None [source]
Pause for the specified number of seconds. This is a convenience function that just calls time.sleep()
- Parameters
seconds (float) – Time interval to pause in seconds.
arcade.quick_run
- arcade.quick_run(time_to_pause: numbers.Number)[source]
Only run the application for the specified time in seconds. Useful for unit testing or continuous integration (CI) testing where there is no user interaction.
- Parameters
time_to_pause (Number) – Number of seconds to pause before automatically closing.
arcade.run
arcade.schedule
- arcade.schedule(function_pointer: Callable, interval: numbers.Number)[source]
Schedule a function to be automatically called every
interval
seconds. The function/callable needs to take a delta time argument similar toon_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]
Specifies the background color of the window. This value will persist for every future screen clears until changed.
- Parameters
color (Color) – List of 3 or 4 bytes 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 screenshake 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
callsset_viewport
by default. If you want to set your own custom viewport during the game, you may need to over-ride this function.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()
) andwindow.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.start_render
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
arcade.View
- class arcade.View(window: Optional[arcade.application.Window] = None)[source]
Support different views/screens in a window.
- on_key_press(symbol: int, modifiers: int)[source]
Override this function to add key press functionality.
- on_key_release(_symbol: int, _modifiers: int)[source]
Override this function to add key release functionality.
- on_mouse_drag(x: float, y: float, dx: float, dy: float, _buttons: int, _modifiers: int)[source]
Override this function to add mouse button functionality.
- Parameters
x (float) – x position of mouse
y (float) – y position of mouse
dx (float) – Change in x since the last time this method was called
dy (float) – 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) pressed during this event. See Modifiers.
- on_mouse_motion(x: float, y: float, dx: float, dy: float)[source]
Override this function to add mouse functionality.
- on_mouse_press(x: float, y: float, button: int, modifiers: int)[source]
Override this function to add mouse button functionality.
- Parameters
x (float) – x position of the mouse
y (float) – 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) pressed during this event. See Modifiers.
- on_mouse_release(x: float, y: float, button: int, modifiers: int)[source]
Override this function to add mouse button functionality.
- 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.
arcade.Window
- class arcade.Window(width: int = 800, height: int = 600, title: str = 'Arcade Window', fullscreen: bool = False, resizable: bool = False, update_rate: Optional[float] = 0.016666666666666666, antialiasing: bool = True, gl_version: Tuple[int, int] = (3, 3), screen: Optional[pyglet.canvas.base.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)[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 update the window.
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
andmouse
attributes available for use.
- property background_color
Get or set the background color for this window.
If the background color is an
RGB
value instead ofRGBA`
we assume alpha value 255.- Type
Color
- clear(color: Optional[Union[Tuple[int, int, int], List[int], 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
- property ctx: arcade.context.ArcadeContext
The OpenGL context for this window.
- Type
- property current_view: Optional[arcade.application.View]
This property returns the current view being shown. To set a different view, call the
arcade.Window.show_view()
method.- Return type
- flip()[source]
Window framebuffers norally 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_viewport() Tuple[float, float, float, float] [source]
Get the viewport. (What coordinates we can see.)
- hide_view()[source]
Hide the currently active view (if any) returning us back to
on_draw
andon_update
functions in the window.This is not necessary to call if you are switching views. Simply call
show_view
again.
- on_key_press(symbol: int, modifiers: int)[source]
Override this function to add key press functionality.
- on_key_release(symbol: int, modifiers: int)[source]
Override this function to add key release functionality.
- on_mouse_drag(x: float, y: float, dx: float, dy: float, buttons: int, modifiers: int)[source]
Override this function to add mouse button functionality.
- Parameters
x (float) – x position of mouse
y (float) – y position of mouse
dx (float) – Change in x since the last time this method was called
dy (float) – 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) pressed during this event. See Modifiers.
- on_mouse_motion(x: float, y: float, dx: float, dy: float)[source]
Override this function to add mouse functionality.
- on_mouse_press(x: float, y: float, button: int, modifiers: int)[source]
Override this function to add mouse button functionality.
- Parameters
x (float) – x position of the mouse
y (float) – 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) pressed during this event. See Modifiers.
- on_mouse_release(x: float, y: float, button: int, modifiers: int)[source]
Override this function to add mouse button functionality.
- 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
- 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]
Shortcut for
arcade.run()
.For example:
MyWindow().run()
Set the caption for the window.
- set_fullscreen(fullscreen: bool = True, screen: Optional[arcade.application.Window] = None, mode: Optional[pyglet.canvas.base.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_mouse_visible(visible: bool = True)[source]
If true, user can see the mouse cursor while it is over the window. Set false, the mouse is not visible. Default is true.
- Parameters
visible (bool) –
- set_update_rate(rate: float)[source]
Set how often the screen should be updated. For example, self.set_update_rate(1 / 60) will set the update rate to 60 fps
- 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) –
- show_view(new_view: arcade.application.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
- test(frames: int = 10)[source]
Used by unit test cases. Runs the event loop a few times and stops.
- Parameters
frames (int) –
arcade.get_screens
arcade.open_window
- arcade.open_window(width: int, height: int, window_title: str, resizable: bool = False, antialiasing: bool = True) arcade.application.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.