@likel0vsky

Как удалить объект с экрана в Pygame?

Пишу игру на PyGame, столкнулся с такой проблемой, как удаление спрайта - нигде в документации, на форумах нет информации о том, как удалить спрайт
Есть метод .kill(), но лично у меня он не работает - перестает работать перемещение объекта и т.д, но с экрана сам объект не удаляется. Как это можно сделать?
Код:
import random
se_tostring = str
import time

import pygame, sys
from pygame.locals import *
pygame.init()
pygame.font.init()

pygame_screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN)
pygame_all_sprites = pygame.sprite.Group()
	#SE FUNCS

def readFile(path):
    return open(path, 'r').read()
def split(str,sep):
    return str.split(sep)

import datetime
now = datetime.datetime.now

pygameObject_bg = pygame.sprite.Sprite(pygame_all_sprites)
try:
   pygameObject_bg.image = pygame.image.load("bg.png")
   pygameObject_bg.rect = pygameObject_bg.image.get_rect()
except Exception:
   print("Файл не найден")
pygameObject_bg_pos = (-1, 0)

pygameObject_bg.rect.x = pygameObject_bg_pos[0]
pygameObject_bg.rect.y = pygameObject_bg_pos[1]
pygameObject_zombie = pygame.sprite.Sprite(pygame_all_sprites)
try:
   pygameObject_zombie.image = pygame.image.load("zomb.png")
   pygameObject_zombie.rect = pygameObject_zombie.image.get_rect()
except Exception:
   print("Файл не найден")
pygameObject_zombie_pos = (50, -10)

pygameObject_zombie.rect.x = pygameObject_zombie_pos[0]
pygameObject_zombie.rect.y = pygameObject_zombie_pos[1]
pygameObjectText_text1 = pygame.font.SysFont( 'serif', 48).render("text", True, (0,0,0) )
pygame_screen.blit( pygameObjectText_text1 , (0,0) )
while True:
      pygame.display.flip()
      pygame.display.update()
      pygame_all_sprites.draw(pygame_screen)	
      for pygame_event in pygame.event.get():
            if pygame_event.type == pygame.KEYDOWN and pygame_event.key == pygame.K_o:
                  pygameObject_zombie_pos = (pygameObject_zombie_pos[0]+5, 0)

                  pygameObject_zombie.rect.x = pygameObject_zombie_pos[0]
                  pygameObject_zombie.rect.y = pygameObject_zombie_pos[1]
            
            if pygame_event.type == pygame.KEYDOWN and pygame_event.key == pygame.K_o:
                  pygameObject_zombie.kill()
  • Вопрос задан
  • 4578 просмотров
Пригласить эксперта
Ответы на вопрос 1
TalismanChet
@TalismanChet
Лицо зла
del pygameObject_zombie
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы