Soy un poco nuevo en python, pero estoy familiarizado con OOP. Intento escribir un juego usando PyGame. Básicamente, mi objetivo es renderizar árboles cada pocos segundos y mover el árbol a través de la pantalla.AttributeError: La instancia de clase no tiene el método __call__
Así que aquí es mi código:
from collections import deque
import pygame,random,sys
pygame.init()
size = 800,600
screen = pygame.display.set_mode(size)
class tree:
def __init__(self):
self.img = pygame.image.load("tree.png")
self.rect = self.img.get_rect()
def render(self):
screen.blit(self.img,self.rect)
def move(self,x,y):
self.rect = self.rect.move(x,y)
#creating a queue of trees
trees = deque()
#appending the first tree on to the queue
trees.append(tree())
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
#appending tree() to trees queue every 300 ms
if pygame.time.get_ticks() % 300 == 0:
trees.append(tree())
#rendering and moving all the tree rects of trees in the queue
for tree in trees:
tree.render()
tree.move(20,2)
pygame.display.flip()
Pero cuando yo haga esto, los primeros árboles se generan con éxito pero luego la ventana PyGame cerradas y me sale este error:
Traceback (most recent call last):
File "error.py", line 25, in <module>
trees.append(tree())
AttributeError: tree instance has no __call__ method
tonto de mí no haber notado eso, gracias! :) –
¡De nada! – Emmanuel