I'm trying to build the snake game using pygame. I'm following this tutorial.
I end up with the following error:
pygame.error: Couldn't open pygame.png
Hey, @ Ali,
It will be very helpful if you can post your code. Though I can suggest you something like better to use Relative paths instead.
current_path = os.path.dirname(__file__) # your .py file is located
current_path = os.path.dirname(__file__) # the resources folder path
image_path = os.path.join(resource_path, 'images') # the image folder path
By doing this, wherever you move the folder containing your .py file, its subdirectories (and therefore whatever they contain) can still be accessed without you having to modify your code.
current_path = os.path.dirname(__file__) # Where your .py file is located
resource_path = os.path.join(current_path, 'resources') # The resource folder path
image_path = os.path.join(resource_path, 'images') # The image folder path
player_image = pygame.image.load(os.path.join(image_path, 'spaceship.png'))
I hope this will be helpful.
I'm trying to build a game using ...READ MORE
Try installing libpng
You can do it with ...READ MORE
You need to download and install the ...READ MORE
pygame.Surface takes in integer values for building ...READ MORE
You must be trying this command in ...READ MORE
file = open('text.txt', 'w+)
You can also use the random library's ...READ MORE
colors = ['red', 'green', ...READ MORE
can you give an example using a ...READ MORE
You can simply the built-in function in ...READ MORE
Already have an account? Sign in.