Reputation: 162
I am trying to load an image with this code:
img_path = os.path.dirname(os.path.realpath(__file__)) + "\\assets\\ms_cell_normal.png"
img = pg.image.load(img_path)
game_display = pg.display.set_mode((WIDTH,HEIGHT))
clock = pg.time.Clock()
while True:
clock.tick(FPS)
for event in pg.event.get():
if event.type == pg.QUIT:
sys.exit(0)
game_display.blit(img, (50,50))
game_display.flip()
Somehow, I get the following error:
Traceback (most recent call last):
File "d:/PythonProjects/MineSweeper/main.py", line 59, in <module>
game_display.flip()
AttributeError: 'pygame.Surface' object has no attribute 'flip'
why ? I read everywhere that this is the way you load images ...
Upvotes: 1
Views: 80
Reputation: 211258
flip()
is not a method of pygame.Surface
. But there is pygame.display.flip()
:
game_display.flip()
pygame.display.flip()
Compared to that blit
is a mehtod of pygame.Surface
and game_display
is an instance of pygame.Surface
:
game_display.blit(img, (50,50))
Notice that you named the Surface associated with the window game_display
when you created it (game_display = pg.display.set_mode((WIDTH,HEIGHT))
)
Upvotes: 2