我正在Pygame制作一款2D平台游戏。
' AttributeError:' NoneType'对象没有属性' add_internal''
此行发生此错误: self.sprites.add(playerbanner)
class Player(pygame.sprite.Sprite):
def __init__(self,classname,movementspeed,jumpheight,damage,x,y,sprites,platforms,bullets,banner,spawndirection):
super().__init__()
self.classname=classname
self.speed=movementspeed
self.height=jumpheight
self.damage=damage
self.x=x
self.y=y
self.banner=banner
self.startdirectionspawn=spawndirection
self.walking=False
self.jumping=False
self.currentframe=0
self.lastupdate=0
self.velocityx=0
self.velocityy=0
self.accelerationy=0
self.lastpress=1
self.loadframes(classname)
self.image=self.stationary
self.rect=self.image.get_rect()
self.rect.center=(self.x,self.y)
self.image.set_colorkey(BLACK)
self.sprites=sprites
self.platforms=platforms
self.bullets=bullets
def countdown(self):
gamecountdown(6)
def updateposition(self,hit,jump):
if self.accelerationy<0:
hit=False
if self.accelerationy!=0:
jump=False
if hit==False:
self.accelerationy+=0.1
if jump==True:
self.accelerationy=-15
if hit==True:
self.velocityy=0
self.velocityx=0
self.accelerationy=0
pressed=pygame.key.get_pressed()
if pressed[pygame.K_a]:
self.velocityx=-self.speed
self.animate('left')
self.lastpress='a'
if pressed[pygame.K_d]:
self.velocityx=self.speed
self.animate('right')
self.lastpress='d'
if not pressed[pygame.K_a] and not pressed[pygame.K_d]:
if self.lastpress=='d':
self.image=self.stationary
elif self.lastpress=='a':
self.image=self.stationarya
self.x+=self.velocityx
self.y+=self.velocityy + (0.2*self.accelerationy)
self.rect.center=(self.x,self.y)
playerbanner=messagedisplay(self.banner,BLACK,self.x-15,self.y-50, 30, 30, 'smallfont')
self.sprites.add(playerbanner)
self.image.set_colorkey(BLACK)
pygame.display.update()
我正在努力让一名玩家1&#39;打印在玩家头上方。当我没有把它放入一个组时,它仍会打印出来,但是会一直闪烁。
从另一个文件调用组打印语句。