作者siudarren504 (PatheticApathy)
看板Python
标题[问题] AttributeError
时间Mon May 6 21:54:45 2019
如题
目前正在练习写一个太空船打陨石的小游戏
以下是我main 里面的程式码,用来确认碰撞的
for i in range(len(game_objects)):
for j in range(i+1, len(game_objects)):
obj_1 = game_objects[i]
obj_2 = game_objects[j]
if not obj_1.dead and not obj_2.dead:
if obj_1.collides_with(obj_2):
obj_1.handle_collision_with(obj_2)
obj_2.handle_collision_with(obj_1)
for to_remove in [obj for obj in game_objects if obj.dead]: to_remove.delete()
game_objects.remove(to_remove)
然後object class的里的__init__() 如下:
class PhysicalObject(pyglet.sprite.Sprite):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.dead = False
self.velocity_x, self.velocity_y = 0.0, 0.0
明明已经有在object 的class 设定了dead,
但当我跑程式时,
却跑出
AttributeError: 'Sprite' object has no attribute 'dead'
请问各位大大有没有人知道是哪里出错了?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 61.223.22.251
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1557150895.A.089.html
1F:推 XperiaZ6C: print出来看看 05/06 22:42
2F:→ djshen: 他不就说了Sprite 05/06 22:55
3F:嘘 hsnuyi: 看过C++括弧少一边的error吗? 05/06 23:47
4F:推 chigi: 'Sprite' object has no attribute 'dead' 05/07 00:55