Skip to content

Commit

Permalink
Allow animated images to persist frame in asset
Browse files Browse the repository at this point in the history
  • Loading branch information
avanwinkle committed Jan 24, 2021
1 parent 22f1023 commit 3f4e963
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mpfmc/assets/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ImageAsset(McAsset):
pool_config_section = 'image_pools' # Will setup groups if present
asset_group_class = ImagePool # Class or None to not use pools

__slots__ = ["frame_skips", "references", "_image"]
__slots__ = ["frame_persist", "frame_skips", "references", "_image"]

def __init__(self, mc, name, file, config):
super().__init__(mc, name, file, config) # be sure to call super
Expand All @@ -205,6 +205,7 @@ def __init__(self, mc, name, file, config):
# you don't need to do anything.

self._image = None # holds the actual image in memory
self.frame_persist = None
self.frame_skips = None
self.references = 0

Expand Down
6 changes: 5 additions & 1 deletion mpfmc/widgets/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,17 @@ def _image_loaded(self, *args) -> None:
if self._image.image.anim_available:
self.fps = self.config['fps']
self.loops = self.config['loops']
self.start_frame = self.config['start_frame']
self.start_frame = self._image.image.anim_index if self._image.frame_persist else self.config['start_frame']
# If not auto playing, set the end index to be the start frame
if not self.config['auto_play']:
# Frame numbers start at 1 and indexes at 0, so subtract 1
self._end_index = self.start_frame - 1
self.play(start_frame=self.start_frame, auto_play=self.config['auto_play'])

# If this image should persist its animation frame on future loads, set that now
if self._image.config.get('persist_frame'):
self._image.frame_persist = True

def _on_texture_change(self, *args) -> None:
"""Update texture from image asset (callback when image texture changes)."""
del args
Expand Down

0 comments on commit 3f4e963

Please sign in to comment.