I'm making a sprite sheet class in pygame and I'm putting every frame I get from an image in an list. But, sometimes the sprite sheet has some empty frames. e.g. I made a image with 2 sprite animation, so I put each one in a row, but the first one is 1 frame bigger than the 2nd one, so the 2nd has a empty frame.
I did this code to check if the frame is empty. I used a reversed loop 'cause most empty frames are at the end of the list, so I can break when any frame is not empty, so then it won't take that much time.
for i in reversed(range(len(frames))):
frame_alpha_as_array = surfarray.array_alpha(frames[i])
if np.sum(frame_alpha_as_array) == 0:
del(frames[i])
else:
break
But, I would like to know if there is a faster way of doing that, so that it doesn't take much of the cpu/gpu/ram (IDK).
I'm relatively new to programing so don't be too harsh if I'm doing something wrong.