Я следую руководству для начинающих, чтобы начать использовать pygame, но у меня застряло отображение спрайтов. Я не могу сделать его видимым на экране. Ниже приведен код, относящийся к спрайту.
Я не могу найти, где я напутал, есть идеи? ?
Мой спрайт — «Снаряд» и определен в классе снарядов, он отправляется игроком, поэтому я добавил метод «launch_projectile», и в основном он должен отображать снаряды.
"Класс снаряда":
import pygame
# Définir la classe projectile
class Projectile(pygame.sprite.Sprite):
# Définir le constructeur de la classe
def __init__(self, player):
super().__init__()
self.velocity = 5
self.image = pygame.image.load('Assets\Blast.png')
#self.image = pygame.transform.scale(self.image, (50, 50))
self.rect = self.image.get_rect()
self.rect.x = player.rect.x + 100
self.rect.y = player.rect.y
"Класс игрока":
def launch_projectile(self):
self.all_projectiles.add(Projectile(self))
"Основной":
while running:
screen.blit(background, (0, 0))
screen.blit(game.player.image, game.player.rect)
game.player.all_projectiles.draw(screen)
if game.pressed.get(pygame.K_RIGHT) and game.player.rect.x + game.player.rect.width < screen.get_width():
game.player.move_right()
elif game.pressed.get(pygame.K_LEFT) and game.player.rect.x > 0:
game.player.move_left()
elif game.pressed.get(pygame.K_UP) and game.player.rect.y > 0:
game.player.move_up()
elif game.pressed.get(pygame.K_DOWN) and game.player.rect.y + game.player.rect.height < screen.get_height():
game.player.move_down()
for event in pygame.event.get():
# Evenement de fermeture de la fenêtre
if event.type == pygame.QUIT:
running = False
# Détecter la touche enfoncée
elif event.type == pygame.KEYDOWN:
game.pressed[event.key] = True
# If space bar
if event.type == pygame.K_SPACE:
game.player.launch_projectile()
elif event.type == pygame.KEYUP:
game.pressed[event.key] = False
Подробнее здесь: https://stackoverflow.com/questions/793 ... ing-pygame
Проблема с тем, что Sprite не отображается при использовании Pygame. ⇐ Python
Программы на Python
1735382322
Anonymous
Я следую руководству для начинающих, чтобы начать использовать pygame, но у меня застряло отображение спрайтов. Я не могу сделать его видимым на экране. Ниже приведен код, относящийся к спрайту.
Я не могу найти, где я напутал, есть идеи? ?
Мой спрайт — «Снаряд» и определен в классе снарядов, он отправляется игроком, поэтому я добавил метод «launch_projectile», и в основном он должен отображать снаряды.
[b]"Класс снаряда":[/b]
import pygame
# Définir la classe projectile
class Projectile(pygame.sprite.Sprite):
# Définir le constructeur de la classe
def __init__(self, player):
super().__init__()
self.velocity = 5
self.image = pygame.image.load('Assets\Blast.png')
#self.image = pygame.transform.scale(self.image, (50, 50))
self.rect = self.image.get_rect()
self.rect.x = player.rect.x + 100
self.rect.y = player.rect.y
[b]"Класс игрока":[/b]
def launch_projectile(self):
self.all_projectiles.add(Projectile(self))
[b]"Основной":[/b]
while running:
screen.blit(background, (0, 0))
screen.blit(game.player.image, game.player.rect)
game.player.all_projectiles.draw(screen)
if game.pressed.get(pygame.K_RIGHT) and game.player.rect.x + game.player.rect.width < screen.get_width():
game.player.move_right()
elif game.pressed.get(pygame.K_LEFT) and game.player.rect.x > 0:
game.player.move_left()
elif game.pressed.get(pygame.K_UP) and game.player.rect.y > 0:
game.player.move_up()
elif game.pressed.get(pygame.K_DOWN) and game.player.rect.y + game.player.rect.height < screen.get_height():
game.player.move_down()
for event in pygame.event.get():
# Evenement de fermeture de la fenêtre
if event.type == pygame.QUIT:
running = False
# Détecter la touche enfoncée
elif event.type == pygame.KEYDOWN:
game.pressed[event.key] = True
# If space bar
if event.type == pygame.K_SPACE:
game.player.launch_projectile()
elif event.type == pygame.KEYUP:
game.pressed[event.key] = False
Подробнее здесь: [url]https://stackoverflow.com/questions/79313617/issue-with-sprite-not-showing-up-using-pygame[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия