Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pyglet - Sprite image and Text label
import pyglet
#index all resources. Resources folder must be on same level as this file.
pyglet.resource.path = ['resources']
pyglet.resource.reindex()
#create window object
screen = pyglet.window.Window(800, 600)
#create player object. Player image must be in resource folder.
player_image = pyglet.resource.image("player.png")
player_sprite = pyglet.sprite.Sprite(img=player_image,x=400,y=300)
#create text label
score_label = pyglet.text.Label(text="Hello World", x=100, y=500)
@screen.event
def on_draw():
screen.clear()
score_label.draw()
player_sprite.draw()
if __name__ == "__main__":
pyglet.app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment