Apr-24-2020, 10:21 PM
For anyone who knows, I'm intending to scale sprites based on the pygame.math.Vector3 z axis. MY question is how to do this in a computationally efficient fashion.
Its a space shooter and I want enemies to scale according to distance (the z axis), but I'm unsure as to the smartest way to do this.
The first option is to have the image scale in the sprites update section. Scaling images for many sprites at a time seems like it could consume a lot of resources and impact FPS.
The other option I'm looking at is to load all the various scaled images into a dictionary via a loop where the value of the z axes are the keys in the dictionary.
Is this a sound approach or is it slower for python to get images from dictionaries like this?
Its a space shooter and I want enemies to scale according to distance (the z axis), but I'm unsure as to the smartest way to do this.
The first option is to have the image scale in the sprites update section. Scaling images for many sprites at a time seems like it could consume a lot of resources and impact FPS.
The other option I'm looking at is to load all the various scaled images into a dictionary via a loop where the value of the z axes are the keys in the dictionary.
fighter_image = pygame.image.load('fighter.png') fighter_scaled_images = {} for z in range(0, 100, 5): img = pygame.trasform.scale(fighter_image, (z, z)) fighter_scaled_images[z] = imgThen the sprite can retrieve the already scaled image from this dictionary. The same could be done with the rotations, but in the case of rotations and scales, I don't know if it is faster for the computer to do it this way that to scale and rotate the original image with the sprite updates.
Is this a sound approach or is it slower for python to get images from dictionaries like this?