Debian Codegraph @

examples/sprite/display_sprite.py

raw symbols SCIP
1 import pyglet
2
3 window = pyglet.window.Window(resizable=True)
4
5 # Set example resource path.
6 pyglet.resource.path = ['../resources']
7 pyglet.resource.reindex()
8
9 # Load example image from resource path.
10 image = pyglet.resource.image("pyglet.png")
11
12 # Anchor point on an image is bottom left corner by default.
13 # Set to center point with anchor properties.
14 image.anchor_x = image.width // 2
15 image.anchor_y = image.height // 2
16
17 # Create basic sprite in the center of the window.
18 sprite = pyglet.sprite.Sprite(image, x=window.width // 2, y=window.height // 2)
19
20 @window.event
21 def on_resize(width, height):
22 # This will keep sprite at the center of the window as it changes size.
23 sprite.update(x=width // 2, y=height // 2)
24
25 @window.event
26 def on_draw():
27 window.clear()
28 sprite.draw()
29
30 pyglet.app.run()