Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow animated images to persist frame in asset #416

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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