Doug123-sketch
Doug123-sketch

Reputation: 11

How do I import a picture and put it on a pygame window

I've been trying for a while now to make a destroyer type game using 'pygame' the main problem I have is importing a picture of a ship to use as the main player. And no matter what I try, I always get the same error

win.blit(win, char, (20, 20), (146, 149))
   TypeError: an integer is required (got type tuple)

And this is my code:

import pygame
pygame.init()
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("First Game")
char = [pygame.image.load('char.png')]
run = True
while run:
    win.fill((0,0,0))
    win.blit(win, char, (20, 20), (146, 149))

    pygame.display.update()

    pygame.quit()

Any help would be appreciated.

Upvotes: 1

Views: 64

Answers (1)

Rabbid76
Rabbid76

Reputation: 210998

blit() is an instance method. Beside the instance of pygame.Surface, the required parameter are the Surface which has to be blit onto the instance of pygame.Surface and the position.

Further more, char is a list of surfaces with on element.

char = [pygame.image.load('char.png')]

Change it to:

char = pygame.image.load('char.png')

and blit the surface char on win:

win.blit(char, (20, 20))

or

pygame.Surface.blit(win, char, (20, 20))

Note, the area parameter (of blit) has to be a rectangle and represents a smaller portion of the source Surface to draw

Upvotes: 1

Related Questions