Open yansnow78 opened 2 years ago
my proposal is based on pgzhelper originally there was just some extra function in pgzhelper.Actor but i think it's better to handle that outside Actor classes this is how it looks like in pgzhelper
@property
def images(self):
@images.setter
def images(self, images):
def load_images(self, sheet_name:str, cols:int, rows:int, cnt:int=0, subrect:pygame.Rect=None):
def sel_image(self, newimage:str):
def sel_image_idx(self, newimage_idx:int):
def next_image(self)-> int:
def animate(self):
add subrect property to Actor.
the goal of subrect is to be able to load a sprite from a sprite-sheet
this property can be a ZRect or pygame.Rect or an objet accepted by pygame.Rect constructor this property can be pass as parameter to the constructor or changed directly
it uses 2 caches for better perfomance: the images loader keep in cache all the subsurface accessed the _surface_cache in Actor keep in cache all the subsurface accessed with their transformed surface (opacted, rotated, ...)
add 3 new classes to do frame animation
add 3 new classes FramesList, FrameBasicAnimation, FrameBasicAnimation feel free to change the names
class FramesList a class use to store frames used by a specific animation it has 3 functions to add frames, all those can be combined
_addFromSheet(self, sheet_name: str, cols: int, rows: int, cnt: int = 0, subrect: CanBeRect = None) to load some frames from a spritesheet
_addFromList(self, frameimages: Sequence[str]) to load some frames from a sequence of image names
_add(self, image: str, subrect: CanBeRect = None): to load one frame from an image or a spritesheet
**class FrameBasicAnimation*** a class used to apply frame to an actor
usage
**class FrameAnimation*** a class used to apply frame to an actor base on fps
usage: example 1 : # play a ball 3d rotation animation during 5 second
example 2 : # play 3 complete animation loop
example 2 : # play infinite animation loop
example 3 : # go to the correct next animation based on delta time