python - pygame - 试图将爆炸矩形分配给老板
问题描述
我的爆炸课看起来像:
class Explosion(Sprite):
def __init__(self, bosss):
super(Explosion, self).__init__()
self.images = []
for num in range(0,6):
img = pygame.image.load(f"C:/Users/x/x/animations/ani{num}.png").convert_alpha()
img = pygame.transform.scale(img, (200, 200))
self.images.append(img)
self.index = 0
self.image = self.images[self.index]
self.rect = self.image.get_rect()
self.x = float(self.rect.centerx)
for boss in bosss.sprites():
self.rect.center = boss.rect.center
self.counter = 0
def update(self,explosion, bosss):
explosion_speed = 4
self.counter += 1
if self.counter >= explosion_speed and self.index < len(self.images) - 1:
self.counter = 0
self.index += 1
self.image = self.images[self.index]
if self.index >= len(self.images) - 1 and self.counter >= explosion_speed:
self.kill()
和我在屏幕上的功能:
def update_screen(ai_settings, screen, player, bosss, deszcz, aliens, starr, new_bullet, boss_bullet,
all_sprites, hpbar, lost, extra_bullet, explosion):
for bullets in new_bullet.sprites():
bullets.draw_pocisk()
player.blitme(hpbar, screen)
# deszcz.draw(screen)
aliens.draw(screen)
if len(aliens) == 0:
bosss.draw(screen)
hpbar.blitme(bosss, boss_bullet)
boss_bullet.draw(screen)
extra_bullet.draw(screen)
hpbar.hit(bosss, new_bullet, boss_bullet, ai_settings, extra_bullet)
player.hit(bosss, boss_bullet, extra_bullet)
if hpbar.Health <=0:
hit = pygame.sprite.groupcollide(new_bullet, bosss, True, True)
explosion.draw(screen)
if hit:
AniExplosion(explosion, bosss)
pygame.mixer.pause()
boss_bullet.empty()
extra_bullet.empty()
if player.health <= 0:
lost.blitme()
pygame.mixer.pause()
boss_bullet.empty()
extra_bullet.empty()
pygame.display.flip()
一切正常,但爆炸显示在左上角,而不是老板的结束位置。
我尝试了所有明显的东西,但我认为我误解了一些东西:/
组也没有矩形,但即使我遍历那个精灵它仍然不起作用。
我认为它甚至没有读过它。有什么建议我可以修复它吗?
解决方案
推荐阅读
- python - Numpy 将一个数组添加到另一个数组
- php - WPForms Lite 错误:未捕获的 RuntimeException:提取失败:变量名称与现有名称冲突
- google-cloud-platform - 向 Google 报告状态时经常出现错误。请求超时
- azure-devops - 在适用于 iOS 15 的 Azdo 管道中构建 Xamarin iOS
- c++ - glTexImage2D 纹理不能以正确的格式读取
- javascript - 从 GitHub 存储库安装包
- airflow - 通过电子邮件发送 bigquery 数据 -airflow
- node.js - NestJS 中的 HTTP Pino 记录器和 Elastic Common Schema (ecs) 格式
- encoding - 我可以在像 H.264 代码这样的 opus 编解码器上设置 pts 和 dts
- r - cjoint 的“conjointDesign”类到数据框