[英]In pygame, what is the most efficient way of resetting every sprite's position?
I'm trying to make a typical platformer using pygame but I'm not exactly sure how I should go about doing a death sequence.我正在尝试使用 pygame制作一个典型的平台游戏,但我不确定我应该如何进行死亡序列。 I want it so after time the player dies every sprite's position is reset to its original position if they moved at all.
我希望它在玩家死亡后每个精灵的位置都重置为其原始位置,如果他们移动了。
I tried experimenting with the pygame.sprite.Group().copy()
but I don't know how to use it or if it even applies to my situation.我尝试尝试使用
pygame.sprite.Group().copy()
但我不知道如何使用它,或者它是否适用于我的情况。
I would store a copy of the original position in the sprite, and then as @furas suggests re-position and re-stat the sprite via a reset()
function.我会在精灵中存储原始位置的副本,然后正如@furas 建议的那样,通过
reset()
函数重新定位和重新统计精灵。
For example:例如:
class ResettableSprite( pygame.sprite.Sprite ):
MAX_HEALTH = 100
def __init__( self, image, x, y ):
pygame.sprite.Sprite.__init__( self )
self.image = image
self.rect = self.image.get_rect()
self.start_x = x
self.start_y = y
self.reset()
def reset( self ):
self.rect.x = self.start_x
self.rect.y = self.start_y
self.health = ResettableSprite.MAX_HEALTH
# ... etc.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.