Skip to content
Anton Hvornum edited this page Oct 26, 2019 · 2 revisions

windowWrapper is a soft wrapper around pyglet.window.Window. And simply adds additional functionality ontop, such as the ability to merge in sprites from different threads.

There's also different pages (or views) that you can add, delete or switch over between. For instance, a loading page, and then transition to a main view.

windowWrapper(width, height, fps=False)

  • width - sets the width of the window
  • height - sets the height of the window
  • fps - Shows or hides a built-in FPS counter.

add_page(name, batch)

Create a new page (buffer/batch), where you can add sprites to. Later on you can switch to this page/context by invoking swap_page(name).

swap_page(name)

Swap page/context to name, this hides all previous elements and transitions to the new view with the elements associated to this view.

add_layer(name)

Create a new layer inside the current page. This is to be able to set sprites/objects behind or infront of each other. This is a extension of pyglet.grapahics.OrderedGroup

remove_layer(name)

Deletes the layer with name identifier. Does also remove all child items(?).

t_add_sprite(name, sprite_obj, sprite_parameters)

Can be called safely from a separate thread, this will setup the sprite_obj in between rendering frames.

  • name - The name of the sprite object
  • sprite_obj - the pointer to the function/class that will be executed to initiate the sprite
  • sprite_parameters - the parameters passed to sprite_obj()

add_sprite(name, sprite_obj)

Add the sprite_obj instance to the local sprite store with the identifier name.
This sprite will be added to the current page and the current default layer.

post_setup

called right after the window is initiated. Useful if you
need to access objects before the first render but after
they've all been setup by the __init__

pre_render

Called every frame just before render() is called.

render

Called every frame, this will re-render the window.
This is done at the maximum possible frame rate (currently no frame-limit is supported).
It will draw every batch in the current page, but also every active sprite not associated with a page.

run

Starts the endless loop keeping everything running (and flushing buffers etc)