鱼C论坛

 找回密码
 立即注册
查看: 1047|回复: 4

pygame打飞机音效为什么还是一直重复?

[复制链接]
发表于 2018-8-8 17:07:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
我按照教程改了代码,为什么还是敌机一被消灭,消灭的音效还是循环播放啊?

        # 绘制大飞机
        for each in big_enemies:
            if each.active:
                each.move()
                if switch_image:
                    screen.blit(each.image1, each.rect)
                else:
                    screen.blit(each.image2, each.rect)
                # 当大飞机进入画面时播放音效
                if each.rect.bottom == -50:
                    enemy3_fly_sound.play(-1)
            else: # 毁灭
                if not(delay % 5):
                    if e3_destroy_index == 0:
                        enemy3_down_sound.play()
                    screen.blit(each.destroy_images[e3_destroy_index],each.rect)
                    e3_destroy_index = (e3_destroy_index + 1) % 6
                    if e3_destroy_index == 0:
                        enemy3_fly_sound.stop()
                        each.reset()


        # 绘制中飞机
        for each in mid_enemies:
            if each.active:
                each.move()
                screen.blit(each.image, each.rect)
            else: # 毁灭
                if not(delay % 5):
                    if e2_destroy_index == 0:
                        enemy2_down_sound.play()
                    screen.blit(each.destroy_images[e2_destroy_index], each.rect)
                    e2_destroy_index = (e2_destroy_index + 1) % 4
                    if e2_destroy_index == 0:
                        each.reset()

        # 绘制小飞机
        for each in small_enemies:
            if each.active:
                each.move()
                screen.blit(each.image, each.rect)
            else:# 毁灭
                if not(delay % 5):
                    if e1_destroy_index == 0:
                        enemy1_down_sound.play()
                    screen.blit(each.destroy_images[e1_destroy_index], each.rect)
                    e1_destroy_index = (e1_destroy_index + 1) % 4
                    if e1_destroy_index == 0:
                        each.reset()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-8-8 18:21:33 | 显示全部楼层
忘了甲鱼老师原来是什么代码了
你的代码也不全,那问题就出在条件上,你的条件是否一直被满足
你的reset对active是否重置
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-8-8 18:24:39 | 显示全部楼层
塔利班 发表于 2018-8-8 18:21
忘了甲鱼老师原来是什么代码了
你的代码也不全,那问题就出在条件上,你的条件是否一直被满足
你的reset ...

我跟着视频一步一步做的,可以说和视频的完全一样,但是就是会出这个bug
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-8 18:26:29 | 显示全部楼层
肯定有敲错的地方,甲鱼老师也是东改西改出来的,你肯定哪里没整对,不行就DOWN个源码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-14 11:13:43 | 显示全部楼层
把你的enemy模块贴出来看下,错误的地方应该是在enemy中reset的属性中没有重置active的属性为True
    def reset(self):
        self.active = True
        self.energy = BigEnemy.energy
        self.rect.left, self.rect.top = \
                        randint(0,self.width - self.rect.width ), \
                        randint(-15 * self.height, -5 * self.height)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-6 06:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表