所以我在pygame中的精灵都有相同的碰撞效果,即使你我把它们分成不同的def,你知道我怎么解决这个问题吗
def render(self,collisionrock):
if (collisionrock==True):
pygame.draw.rect(window,red,(150,150,100,100)) #for some reason this wont work
window.blit(self.i1, (self.x,self.y))
def render(self,collisionguy):
if (collisionguy==True):
font = pygame.font.Font(None, 50)
text = font.render("YOU WIN", 1, (10, 10, 10)) #they would all apply this line
textpos = text.get_rect() #of code
textpos.centerx = window.get_rect().centerx
window.blit(text, textpos)
window.blit(self.i1, (self.x,self.y))
else:
window.blit(self.i1, (self.x,self.y))
在sprite类中似乎有两个同名的方法“render”
在这种情况下,Python将忽略第一个方法(具有collisionrock参数),而只使用第二个定义。似乎是这样
您可以将第一个“render”重命名为“render\u with \u rock\u collision”,第二个“render”重命名为“render\u with \u guy\u collision”
还有一件事。而不是
你可以写:
让Guido Van Rossum开心
相关问题 更多 >
编程相关推荐