add subrect property to Actor and 3 new class to do frame animation #278
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, frame_images: 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