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 rectangle outside surface area Here is the code used to rotate an image:

Installation of pygame with Anaconda

The easiest way to install Python using conda is: conda install -c https://conda.binstar.org/krisvanneste pygame Edit (03/2016): It seems like the package is unavailable, but you can use this instead: conda install -c https://conda.anaconda.org/tlatorre python Edit (01/2017) The command has changed, now you can use: conda install -c tlatorre pygame=1.9.2 Edit (07/2018) tlatorre’s repo is still …

Read more

How to use pygame.KEYDOWN to execute something every time through a loop while the key is held down?

Use pygame.KEYDOWN and pygame.KEYUP to detect if a key is physically pressed down or released. You can activate keyboard repeat by using pygame.key.set_repeat to generate multiple pygame.KEYDOWN events when a key is held down, but that’s rarely a good idea. Instead, you can use pygame.key.get_pressed() to check if a key is currently held down:

How do I maximize the display screen in PyGame?

To become fullscreen at native resolution, do To make the window resizeable, add the pygame.RESIZABLE parameter when seting the mode. You can set the mode of the screen surface multiple times but you might have to do pygame.display.quit() followed by pygame.display.init() You should also check the pygame documentation here http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode

How can I create a text input box with Pygame?

You can define a rect as the area of the input box. If a pygame.MOUSEBUTTONDOWN event occurs, use the colliderect method of the input_box rect to check if it collides with the event.pos and then activate it by setting a active variable to True. If the box is active you can type something and Pygame will generate pygame.KEYDOWN events which have a unicode attribute that you can simply add to a string, …

Read more

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 to know what fonts can I use with …

Read more

Pygame mouse clicking detection

I assume your game has a main loop, and all your sprites are in a list called sprites. In your main loop, get all events, and check for the MOUSEBUTTONDOWN or MOUSEBUTTONUP event. So basically you have to check for a click on a sprite yourself every iteration of the mainloop. You’ll want to use mouse.get_pos() and rect.collidepoint(). Pygame does not offer event …

Read more