Questions tagged [pygame]

Pygame is a set of Python modules designed for writing video games. Use this tag only if you are using the Pygame library and not if you have a question about programming a game in Python in general.

Pygame is a free Python library released under the Lesser General Public License (GNU LGPL) version 2.1 (according to its GitHub page), aimed at creating video games. It's built on top of , is highly portable and runs on nearly every platform and operating system.

References

Documentation

Games using Pygame

19430 questions
33
votes
6 answers

How to Center Text in Pygame

I have some code: # draw text font = pygame.font.Font(None, 25) text = font.render("You win!", True, BLACK) screen.blit(text, [SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2]) How can I get the text's width and height, so I can center text like…
Xerath
  • 1,069
  • 5
  • 17
  • 26
32
votes
5 answers

How can I create a text input box with Pygame?

I want to get some text input from the user in Python and display what they are typing in a text box, and when they press enter, it gets stored in a string. I've looked everywhere, but I just can't find anything. I'm using Pygame.
Deps
  • 555
  • 1
  • 4
  • 12
32
votes
5 answers

What fonts can I use with pygame.font.Font?

I thought that pygame.font.Font was to load .ttf fonts, and that you can't load a font without having the .ttf file in the same directory, but I have seen a video where someone load a font without having the .ttf font in the same directory. I want…
Edu Grando
  • 435
  • 1
  • 4
  • 5
31
votes
7 answers

Pygame on Android

I was wondering if someone could give me a detailed explanation on how to run a game/app developed using Pygame on an Android phone. I recently finished programming PacMan and it works perfectly on my computer, but I think it would be awesome if I…
30
votes
10 answers

Installation of pygame with Anaconda

I have Anaconda 1.6.2, which uses Python 2.7.5, installed on a Windows 7 64-bit system. I need to install Pygame 1.9.1 and this is not part of the conda repository. I cannot run the Windows installer because Anaconda has not made registry entries…
radhanila
  • 403
  • 1
  • 5
  • 8
29
votes
9 answers

Where can I find and install the dependencies for pygame?

I am relatively new to linux and am trying to install the pygame dev environment for python. When I run the setup.py it says that I need to install the following dependencies, one of which I found and installed (SDL). However, the others have been…
Andy
  • 1,159
  • 5
  • 15
  • 19
29
votes
5 answers

pygame installation issue in mac os

I have following issue of installing pygame package. In file included from src/_numericsurfarray.c:23: src/pygame.h:106:10: fatal error: 'SDL.h' file not found #include ^ 1 error generated. error: Setup script exited with error:…
J4cK
  • 30,459
  • 8
  • 42
  • 54
29
votes
10 answers

SVG rendering in a Pygame application. Prior to Pygame 2.0, Pygame did not support SVG. Then how did you load it?

In a Pygame application, I would like to render resolution-free GUI widgets described in SVG. How can I achieve this? (I like the OCEMP GUI toolkit, but it seems to be bitmap-dependent for its rendering.)
Pierre-Jean Coudert
  • 9,109
  • 10
  • 50
  • 59
29
votes
5 answers

Allowing resizing window pyGame

I am trying to allow resizing for this app, I put the RESIZABLE flag, but when I try to resize, it messes up! Try my code. It is a grid program, when the window resizes I want the grid to also resize/shrink. import pygame,math from pygame.locals…
user1513192
  • 1,123
  • 4
  • 17
  • 29
28
votes
16 answers

Pygame, sounds don't play

I'm trying to play sound files (.wav) with pygame but when I start it I never hear anything. This is the code: import pygame pygame.init() pygame.mixer.init() sounda= pygame.mixer.Sound("desert_rustle.wav") sounda.play() I also tried using…
kettlepot
  • 10,574
  • 28
  • 71
  • 100
28
votes
2 answers

Python Exception in thread Thread-1 (most likely raised during interpreter shutdown)?

My friend and I have been working on a large project to learn and for fun in python and PyGame. Basically it is an AI simulation of a small village. we wanted a day/night cycle so I found a neat way to change the color of an entire surface using…
Nick Jarvis
  • 361
  • 1
  • 3
  • 9
27
votes
5 answers

is it possible to run pygame or pyglet in a browser?

I have 3 game libraries installed on my PC: pyglet, pygame and Panda3D. I would like to create a 2D game and make it a web browser game so i can put it on facebook. I know that Panda3D has a web-browser-plugin. Panda3D is for 3D games…
Lynob
  • 5,059
  • 15
  • 64
  • 114
27
votes
3 answers

Non-blocking I/O with asyncio

I'm trying to write a networked game with Pygame and asyncio, but I can't work out how to avoid hanging on reads. Here is my code for the client: @asyncio.coroutine def handle_client(): print("Connected!") reader, writer = yield from…
rlms
  • 10,650
  • 8
  • 44
  • 61
27
votes
3 answers

A bit confused with blitting (Pygame)

I've just started learning some pygame (quite new to programming overall), and I have some very basic questions about how it works. I haven't found a place yet that explains when I need to blit or not to include a certain surface on the screen. For…
Pabce
  • 1,429
  • 2
  • 13
  • 12
26
votes
1 answer

What is the surface.blit() function in pygame? What does it do? How does it work?

I am a beginner in Python and I am not clear about the function surface.blit(). What does it do? How does it works? I have come across the following points as to how to create it. Create a canvas of desired size Create a surface of smaller size…
Lavina Khushlani
  • 509
  • 2
  • 7
  • 14