When I try to run the game it freezes and I get an error.

the Code:

bif = "bg.jpg"
mif = "ball.png"

import pygame, sys
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((800, 600), 0, 32)

background = pygame.image.load(bif).covert()
mouse_c = pygame.image.load(mif).covert_alpha()

while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()

screen.blit(background, (0, 0))

x, y = pygame.mouse.get_pos()
x -= mouse_c.get_width()/2
y -= mouse_c.get_height()/2

screen.blit(mouse_c, (x, y))

pygame.display.update()

the Error Message:

Traceback (most recent call last):
File "J:\Python\Game.py", line 10, in <module>
background = pygame.image.load(bif).covert()
AttributeError: 'pygame.Surface' object has no attribute 'covert'

If I comment out line 10, it has a similar problem with line 11, as well:

Traceback (most recent call last):
File "J:\Python\Game.py", line 11, in <module>
mouse_c = pygame.image.load(mif).covert_alpha()
AttributeError: 'pygame.Surface' object has no attribute 'covert_alpha'

I'm using Python ver. 2.5.4 and Pygame ver. 2.5.4 for Windows (though I've tried many different versions of both, it hasn't solved the problem)

I have no idea what's wrong. Can someone please help? I'm very new, so if you know what my problem is I'd love it if you could explain it simply, and in depth. If it has something to do with the directory, please inform me as to where to access it/how exactly to edit it, so I can alleviate the problem (just to give a hypothetical example). Thanks.

Recommended Answers

All 2 Replies

The AttributeError is telling you that the instance of X lacks Y. If you study your error message:

background = pygame.image.load(bif).covert()
AttributeError: 'pygame.Surface' object has no attribute 'covert'

It first gives you the line of code for context, then the actual error (AttributeError). So it says the pygame.Surface object does not have an attribute called 'covert'. Looking back at the line of code you can deduce that pygame.image.load() returns a pygame object called a Surface. By tacking on covert() you're trying to access the attribute contained therein.

At this point, you could look into the pygame documentation and see that the Surface object does indeed NOT have a covert or covert_alpha method, but it does have convert and convert_alpha.

EDIT: Welcome to DaniWeb, I hope you enjoy your stay :)

I think what you are looking for is:

background = pygame.image.load(bif).convert()
# notice that pygame surfaces use 'convert' not 'covert'.
# it's just a simple syntax error. also, out of curiosity, why are you
# converting your background to support alpha transparency?
# Unless you are drawing image behind 'background', there is no
# need to convert it

hope that helps!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.