A
A
Alexander Nikolaev2022-02-19 21:58:38
pygame
Alexander Nikolaev, 2022-02-19 21:58:38

Why is the sprite not being rendered in pygame?

Why is the sprite not being drawn?

import pygame
import sys
from gun import Gun

def run():

    pygame.init()
    screen = pygame.display.set_mode((1200, 600))
    pygame.display.set_caption("Космические психи")
    bg_color = (0, 0, 0)
    gun = Gun(screen)

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

    screen.fill(bg_color)
    gun.output()
    pygame.display.flip()


run()

import pygame

class Gun():

    def __init__(self, screen):
        """инициализауия пушки"""

        self.screen = screen
        self.image = pygame.image.load('images/kosmpsih.png')
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()
        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom = self.screen_rect.bottom

    def output(self):
        """отрисовка пушки"""

        self.screen.blit(self.image, self.rect)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
YariKartoshe4ka, 2022-02-24
@YariKartoshe4ka

screen.fill(bg_color)
gun.output()
pygame.display.flip()

Lies outside the while loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question