P
P
Pavel Pavel2020-04-30 19:37:06
Python
Pavel Pavel, 2020-04-30 19:37:06

Image not showing in pygame?

import image, no errors

import pygame
FPS = 60
W = 700  # ширина экрана
H = 300  # высота экрана
WHITE = (255, 255, 255)

LEFT="to the left"
RIGHT="to the right"
UP="to the up"
DOWN="to the down"
STOP="stop"


pygame.init()
sc = pygame.display.set_mode((W, H))
clock = pygame.time.Clock()
x = W // 2
y = H // 2
w=30
h=30
motion=STOP
image = pygame.image.load('C:\\Users\\Pavel\\Desktop\\game\\image.png').convert()
while 1:
    sc.fill(WHITE)

    pygame.display.update()
 
    for i in pygame.event.get():
        sc.blit(image, [x, y])
        if i.type == pygame.QUIT:
            exit()
        elif y==0:
            y=1
        elif i.type == pygame.KEYDOWN:
            if i.key == pygame.K_LEFT:
                motion=LEFT
            elif i.key == pygame.K_RIGHT:
                motion=RIGHT
        
            elif i.key == pygame.K_DOWN:
                motion=DOWN
            elif i.key == pygame.K_UP:
                motion=UP
            elif i.mod == pygame.KMOD_LSHIFT:
                y+=50
        if motion==LEFT:
            x-=3
        elif motion==RIGHT:
            x+=3
        elif motion==UP:
            y-=3
        elif motion==DOWN:
            y+=3
    pygame.time.delay(60)
    pygame.display.flip()

I thought that the picture was big, I set the resolution of the picture to 34 pixels by 17, but it did not give any results

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DUDE, 2020-04-30
@Pav3lpy

Because you add an image in a loop where you check events. Add it after you paint it white.

...
while 1:
    sc.fill(WHITE)
    sc.blit(image, [x, y])
    ...
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question