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
22
votes
6 answers

In Python, how can I detect whether the computer is on battery power?

I'm playing around with pygame, and one thing I'd like to do is reduce the number of frames per second when the computer is on battery power (to lower the CPU usage and extend battery life). How can I detect, from Python, whether the computer is…
Joe White
  • 94,807
  • 60
  • 220
  • 330
22
votes
1 answer

What is the difference between super() with arguments and without arguments?

I encountered a code which uses the super() method in 2 different ways, and I can't understand what's the difference in the logic. I'm learning right now the pygame module and I got a task to create a class of a Ball which inherits from Sprite…
Jhon Margalit
  • 451
  • 4
  • 12
22
votes
12 answers

Rendering text with multiple lines in pygame

I am trying to make a game and I am trying to render a lot of text. When the text renders, the rest of the text goes off the screen. Is there any easy way to make the text go to the next line of the pygame window? helpT = sys_font.render \ …
Daniel Maslia
  • 235
  • 1
  • 2
  • 7
22
votes
4 answers

pygame clock.tick() vs framerate in game main loop

Every pygame has a game loop that looks like this: while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False pygame.display.flip() print("tick " +…
ERJAN
  • 23,696
  • 23
  • 72
  • 146
22
votes
8 answers

Countdown timer in Pygame

I started using pygame and I want to do simple game. One of the elements which I need is countdown timer. How can I do the countdown time (eg 10 seconds) in PyGame?
adamo94
  • 507
  • 1
  • 6
  • 15
22
votes
6 answers

How do I change the pygame icon?

Does anyone know how to change the pygame icon? I found a thing on the pygame website that lets you do this, but when I try it, it just makes the pygame window very small.
user2883997
  • 231
  • 1
  • 3
  • 9
22
votes
7 answers

Pygame installation for Python 3.3

I am trying to import Pygame to use for my version of Python, 3.3. The downloads on the Pygame website only have Python 3.1 and 3.2. I cannot seem to be able to import Pygame though I thought I had it installed in the correct path. I have tried both…
ShroomBandit
  • 441
  • 1
  • 5
  • 12
21
votes
6 answers

How can I convert pygame to exe?

Recently, I made a pygame game. I want to show it to my friends. But unfortunately, I cant make an executable file, only a .py file. I have tried to use tools such as py2exe which might not support Python 3.6 and pyinstaller. I think pyinstaller may…
Bili Nico
  • 211
  • 1
  • 2
  • 3
20
votes
2 answers

pygame multithread client socket GUI Blocking

I want to write a gomoku game with server and client. The terminal version works well, but pygame version just blocked and can't rend anything. Here is the game execute function First it start a socket connection self._running = True in init,…
Aries_is_there
  • 386
  • 2
  • 13
20
votes
3 answers

How to distinguish left click , right click mouse clicks in pygame?

From api of pygame, it has: event type.MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION But there is no way to distinguish between right, left clicks?
ERJAN
  • 23,696
  • 23
  • 72
  • 146
19
votes
2 answers

Pygame level/menu states

With my code below what would be the simplest and easiest way to implement game states to control levels? If I wanted to start with a title screen then load a level, and proceed to the next level on completion? If someone could explain the easiest…
user1758231
  • 1,001
  • 3
  • 14
  • 20
18
votes
4 answers

How can I draw images and sprites in Pygame?

How can I draw images using Pygame? I know how to load them. I have made a blank window. When I use screen.blit(blank, (10,10)), it does not draw the image and instead leaves the screen blank.
jtl999
  • 1,115
  • 2
  • 10
  • 17
18
votes
1 answer

pyGame full core usage in simple loop

Edit This is an open issue and appears to be related to alsa audio. A workaround is to shutdown the audio mixer, or install pyGame from source. pygame.init() pygame.mixer.quit() I am just beginning development with pyGame and have found that I…
Matt Clark
  • 27,671
  • 19
  • 68
  • 123
18
votes
9 answers

Is Python and pygame a good way to learn SDL?

If I want to move to C++ and SDL in the future, is Python and pygame a good way to learn SDL?
Not
18
votes
3 answers

Pygame window not responding after a few seconds

This simple piece of code crashes (the window is not responding) after a few seconds (around 5). import pygame from pygame.locals import * pygame.init() screen = pygame.display.set_mode((640, 480), 0, 24) #clock = pygame.time.Clock() #font =…
Fred
  • 901
  • 1
  • 8
  • 16