Trouble Installing Pygame on Mac OSX

The instructions differ if you have a 32-bit proccessor or a 64-bit one. Users of 32-bit processors should just download and install the binary labeled pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg on the pygame download page. Users of 64-bit processors should follow the instructions below. There is no 64-bit version of pygame for Mac OS X. The 32-bit version of … Read more

Running Python code contained in a string

You can use the eval(string) method to do this. Definition eval(code, globals=None, locals=None) The code is just standard Python code – this means that it still needs to be properly indented. The globals can have a custom __builtins__ defined, which could be useful for security purposes. Example eval(“print(‘Hello’)”) Would print hello to the console. You … Read more

Chinese unicode fonts in PyGame

pygame uses SDL_ttf for rendering, so you should be in fine shape as rendering goes. unifont.org appears to have some extensive resources on Open-Source fonts for a range of scripts. I grabbed the Cyberbit pan-unicode font and extracted the encluded ttf. The folowing ‘worked on my machine’ which is a Windows Vista Home Basic and … Read more

How to remove/replace text in pygame

You have to erase the old text first. Surfaces created by Font.render are ordinary surfaces. Once a Surface is blit, its contents become part of the destination surface, and you have to manipulate the destination surface to erase whatever was blit from the source surface. One way to erase the destination surface is to blit … Read more

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

Click events if event.type == pygame.MOUSEBUTTONDOWN: print(event.button) event.button can equal several integer values: 1 – left click 2 – middle click 3 – right click 4 – scroll up 5 – scroll down Fetching mouse state Instead of waiting for an event, you can get the current button state as well: state = pygame.mouse.get_pressed() This … Read more

Changing colour of a surface without overwriting transparency

You can achieve this by 2 steps. self.original_image contains the filled rectangle with the desired color: self.original_image.fill(self.colour) Generate a completely white rectangle and transparent areas. Blend the rectangle with (self.image) and the blend mode BLEND_MAX (see pygame.Surface.blit): whiteTransparent = pg.Surface(self.image.get_size(), pg.SRCALPHA) whiteTransparent.fill((255, 255, 255, 0)) self.image.blit(whiteTransparent, (0, 0), special_flags=pg.BLEND_MAX) Now the rectangle is completely white, … Read more