鱼C论坛

 找回密码
 立即注册
查看: 1097|回复: 1

86讲 pygame动画精灵

[复制链接]
发表于 2020-8-25 10:15:36 | 显示全部楼层 |阅读模式

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

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

x
跟着小甲鱼老师敲的代码,出现了超出最大递归深度的异常
  1. import pygame
  2. import sys
  3. from pygame.locals import *
  4. import random

  5. #pygame.sprite.Sprite动画精灵类
  6. class Ball(pygame.sprite.Sprite):
  7.     def ___init__(self, image, pos, speed):
  8.         pygame.sprite.Sprite.__init__(self)

  9.         self.image = pygame.image.load(image).convert_alpha()
  10.         self.rect = self.image.get_rect()
  11.         self.rect.left, self.rect.top = pos
  12.         self.speed = speed
  13. ##        self.width, self.height = bg_size[0], bg_size[1]

  14. def main():
  15.     pygame.init()

  16.     ball_image = '173303o7gm7x5b57f972gz.png'
  17.     bg_image = '173302oeettatvv00vv3bu.png'
  18.    
  19.     running = True

  20.     bg_size = width, height = 1024, 681
  21.     screen = pygame.display.set_mode(bg_size)
  22.     pygame.display.set_caption('play the ball')
  23.     background = pygame.image.load(bg_image).convert_alpha()
  24.     balls = []

  25.     for i in range(5):
  26.         pos = random.randint(0, width - 100), random.randint(0, height - 100)
  27.         speed = [random.randint(-10, 10), random.randint(-10, 10)]
  28.         print(2)
  29.         ball = Ball(ball_image, pos, speed)
  30.         print(1)
  31.         balls.append(ball)

  32.     clock = pygame.time.Clock()
  33.     while running:
  34.         for event in pygame.event.get():
  35.             if event.type == QUIT:
  36.                 sys.exit()
  37.         screen.blit(background, (0, 0))

  38.         for each in balls:
  39.             screen.blit(each.image, each.rect)

  40.         pygame.display.flip()
  41.         clock.tick(30)

  42. if __name__ == "__main__":
  43.     main()
复制代码

以上是我的代码,求大神康康孩子吧
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-25 10:26:35 | 显示全部楼层

                               
登录/注册后可看大图
这个是我的异常
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-28 04:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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