I am developing a game in pygame and everything is working. But I thought of something and wasn't sure if it mattered.
My game makes use of projectiles using the sprite class and currently code looks like this
class Enemy_Attack_Sprite(pygame.sprite.Sprite):
def __init__(self, image, w=200, h=20):
pygame.sprite.Sprite.__init__(self)
image_load = pygame.image.load(image)
self.image = pygame.transform.smoothscale(image_load,(w,h))
With 'Image' being the file name as string. So I would call
projectile = Enemy_Attack_Sprite('projectile.png')
Does that mean every single time a shot is fired the programe is loading the .png again? would it be more efficient or make a significant difference to do it like this:
projectile_image = pygame.image.load('projectile.png')
class Enemy_Attack_Sprite(pygame.sprite.Sprite):
def __init__(self, image, w=200, h=20):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.transform.smoothscale(image,(w,h))
and then call it with:
projectile = Enemy_Attack_Sprite(projectile_image)
Everything is working okay now, But I'm wondering if re-writing the images and sprite functions in my game would make a difference in performance?