【发布时间】:2019-08-18 08:13:40
【问题描述】:
我正在使用 Pygame 尝试将一个类作为参数传递给函数,这样我就可以调用该方法,而不是整个类。每次我通过 class 参数时,它似乎都会运行该类,并且由于它处于循环状态,因此很快就会将其磨碎。任何人都可以帮忙吗?我的代码结构还好吗?我试图从组中删除雨滴,然后生成一个新行,但现在,只是想办法从组中删除雨滴。谢谢!!!顺便说一句,对 Python 和一般编码(不包括 HTML5 和 CSS3)有点陌生。
我已尝试将类设置为变量 (drop = Droplet()),然后尝试运行要删除的函数。我还尝试将类中的函数设置为方法,但也失败了。我真的很感激任何帮助。谢谢!我对 Stack Overflow 和 Google 进行了详尽的研究。我试过 .kill 和 .remove。
class Droplet(Sprite):
def __init__(self):
super(Droplet, self).__init__(rainfall)
self.screen = screen
self.screen_rect = screen.get_rect
self.image = pygame.image.load('images/Glossy_Raindrop.bmp')
self.rect = self.image.get_rect()
self.rect.x = self.rect.width
self.rect.y = self.rect.height
def blitme(self):
self.screen.blitme(self.image, self.rect)
def dropground(Droplet):
drop = Droplet()
screenie = screen.get_rect()
if not screen.get_rect().contains(drop.rect):
print("delete")
drop.kill()
def update_screen(rainfall):
screen.fill((135, 206, 235))
print(len(rainfall))
rain_y_move(Droplet, rainfall)
dropground(Droplet)
rainfall.draw(screen)
pygame.display.flip()
最终我一次产生了大量的雨滴,这减慢了它的速度。我希望它删除组中的雨滴,然后从那里开始并生成一个新行。就像在屏幕上下雨一样。
【问题讨论】:
标签: python class methods pygame