Could not open resource file, pygame error: “FileNotFoundError: No such file or directory.”

The resource (image, font, sound, etc.) file path has to be relative to the current working directory. The working directory is possibly different from the directory of the python file. It is not enough to put the files in the same directory or sub directory. You also need to set the working directory. Alternatively, you … Read more

How to detect collisions between two rectangular objects or images in pygame

Use pygame.Rect objects and colliderect() to detect the collision between the bounding rectangles of 2 objects or 2 images: rect1 = pygame.Rect(x1, y1, w1, h1) rect2 = pygame.Rect(x2, y2, w2, h2) if rect1.colliderect(rect2): # […] If you have to images (pygame.Surface objects), the bounding rectangle of can be get by get_rect(), where the location of … Read more

pygame installation issue in mac os

Here (OSX Mavericks) I got able to install this way: brew install sdl sdl_image sdl_mixer sdl_ttf portmidi pip install https://bitbucket.org/pygame/pygame/get/default.tar.gz (“default” branch is on commit e3ae850 right now) Source: https://bitbucket.org/pygame/pygame/issue/139/sdlh-not-found-even-thought-it-exists#comment-3822470 See this other StackOverflow question too: PyGame in a virtualenv on OS X with brew?

How to get keyboard input in pygame?

You can get the events from pygame and then watch out for the KEYDOWN event, instead of looking at the keys returned by get_pressed()(which gives you keys that are currently pressed down, whereas the KEYDOWN event shows you which keys were pressed down on that frame). What’s happening with your code right now is that … Read more