天边一抹灬红 发表于 2020-8-25 10:15:36

86讲 pygame动画精灵

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

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

      self.image = pygame.image.load(image).convert_alpha()
      self.rect = self.image.get_rect()
      self.rect.left, self.rect.top = pos
      self.speed = speed
##      self.width, self.height = bg_size, bg_size

def main():
    pygame.init()

    ball_image = '173303o7gm7x5b57f972gz.png'
    bg_image = '173302oeettatvv00vv3bu.png'
   
    running = True

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

    for i in range(5):
      pos = random.randint(0, width - 100), random.randint(0, height - 100)
      speed =
      print(2)
      ball = Ball(ball_image, pos, speed)
      print(1)
      balls.append(ball)

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

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

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

if __name__ == "__main__":
    main()

以上是我的代码,求大神康康孩子吧

天边一抹灬红 发表于 2020-8-25 10:26:35

https://s1.ax1x.com/2020/08/25/d6J3vQ.png这个是我的异常
页: [1]
查看完整版本: 86讲 pygame动画精灵