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
48
votes
12 answers

Why does it say that module pygame has no init member?

This is the code I have: import pygame pygame.init() I'm very confused because if I try to run the file, then there seems to be no issue, but pylint says the following: E1101:Module 'pygame' has no 'init' member I have searched thoroughly for a…
Ludde
  • 481
  • 1
  • 4
  • 3
48
votes
6 answers

How do I rotate an image around its center using Pygame?

I had been trying to rotate an image around its center in using pygame.transform.rotate() but it's not working. Specifically the part that hangs is rot_image = rot_image.subsurface(rot_rect).copy(). I get the exception: ValueError: subsurface…
Miha
  • 501
  • 1
  • 4
  • 4
48
votes
10 answers

HSV to RGB Color Conversion

Is there a way to convert HSV color arguments to RGB type color arguments using pygame modules in python? I tried the following code, but it returns ridiculous values. import colorsys test_color = colorsys.hsv_to_rgb(359, 100,…
AvZ
  • 997
  • 3
  • 14
  • 25
48
votes
4 answers

Pygame mouse clicking detection

I was wondering how to write code that would detect the mouse clicking on a sprite. For example: if #Function that checks for mouse clicked on Sprite: print ("You have opened a chest!")
user1406948
47
votes
5 answers

Differences between Python game libraries Pygame and Pyglet?

I've had some experience with Pygame, but there seems to be a lot of buzz around Pyglet these days. How do these two libraries compare? What would be the advantage of using one over the other, both in features and ease of use? Finally, would you say…
nakedfanatic
  • 3,108
  • 2
  • 28
  • 33
44
votes
3 answers

Start with pyglet or pygame?

I would like to know what is the best to start with, pyglet or pygame? Which one is faster and which one is more active? I would also like to know if pyglet will get python 3 support, because I have read here that it might not be possible or it…
Reshure
  • 3,295
  • 5
  • 28
  • 26
41
votes
5 answers

How do I maximize the display screen in PyGame?

I am new to Python programming and I recently started working with the PyGame module. Here is a simple piece of code to initialize a display screen. My question is : Currently, the maximize button is disabled and I cannot resize the screen. How do I…
39
votes
5 answers

Play WAV file in Python

I tried PyGame for playing a WAV file like this: import pygame pygame.init() pygame.mixer.music.load("mysound.wav") pygame.mixer.music.play() pygame.event.wait() but It change the voice and I don't know why! I read this link solutions and can't…
nim4n
  • 1,813
  • 3
  • 21
  • 36
38
votes
13 answers

Does PyGame do 3d?

I can't seem to find the answer to this question anywhere. I realize that you have to use PyOpenGL or something similar to do OpenGL stuff, but I was wondering if its possible to do very basic 3D graphics without any other dependencies.
eggbert
  • 3,105
  • 5
  • 30
  • 39
38
votes
7 answers

How to know the angle between two vectors?

I am making small game with pygame and I have made a gun that rotates around its center. My problem is that I want the gun to rotate by itself to the enemy direction, but I couldn't do that because I can't find the angle between the gun and the…
38
votes
5 answers

How do I detect collision in pygame?

I have made a list of bullets and a list of sprites using the classes below. How do I detect if a bullet collides with a sprite and then delete that sprite and the bullet? #Define the sprite class class Sprite: def __init__(self,x,y, name): …
Mike Schmidt
  • 945
  • 3
  • 12
  • 31
37
votes
2 answers

Pygame water ripple effect

I have Googled for it but there are no ready scripts - as opposed to the same effect on Flash. I have checked the algorithm on The Water Effect Explained and also tested an implementation of the Perlin Noise, which provides a good simulation of the…
planestepper
  • 3,277
  • 26
  • 38
36
votes
10 answers

Problems getting pygame to show anything but a blank screen on Macos

I recently bought a new macbook and I've been trying endlessly to get pygame to work, but haven't succeeded yet. I'm getting pretty desperate and I could really use some help. I've installed pygame 1.9.4 and even though I don't get any error…
Boudewijn Maas
  • 399
  • 1
  • 3
  • 10
36
votes
11 answers

Process finished with exit code -1073741515 (0xC0000135)

I'm running a python script and it used to work (it even does on my other laptop right now) but not on my current computer - I just get the error code: Process finished with exit code -1073741515 (0xC0000135) I don't get any other results - not…
Cribber
  • 2,513
  • 2
  • 21
  • 60
34
votes
7 answers

How can I play an mp3 with pygame?

import pygame file = 'some.mp3' pygame.init() pygame.mixer.init() pygame.mixer.music.load(file) pygame.mixer.music.play() This outputs, "Process finished with exit code 0", but it doesn't play anything. How can I resolve this problem?
Ashot
  • 521
  • 2
  • 6
  • 15