fixed repeat of animations, fix memory leak
This commit is contained in:
parent
8660cb5225
commit
28d971bf8f
2 changed files with 31 additions and 8 deletions
|
@ -175,6 +175,7 @@ class RenderingLayer:
|
|||
def __init__(self, animations, frame_rate=40):
|
||||
self.animations = animations
|
||||
self.current_point_array = []
|
||||
self.current_animation = {}
|
||||
self.current_animation_action = {}
|
||||
self.frame_rate = frame_rate # Set the desired frame rate
|
||||
self.frame_duration = 1.0 / frame_rate # Calculate the frame duration
|
||||
|
@ -189,6 +190,7 @@ class RenderingLayer:
|
|||
self.play_animation(animation)
|
||||
|
||||
def play_animation(self, animation):
|
||||
self.current_animation = animation
|
||||
if len(self.animation_queue) > 0:
|
||||
print("Stopping current animation...")
|
||||
# Replace the currently playing animation with the new one
|
||||
|
@ -232,7 +234,7 @@ class RenderingLayer:
|
|||
imagingtime = 0
|
||||
interpolatetime = 0
|
||||
transitionFrameCount = 1
|
||||
|
||||
offscreen_canvas = matrix.CreateFrameCanvas()
|
||||
|
||||
while True:
|
||||
|
||||
|
@ -240,7 +242,7 @@ class RenderingLayer:
|
|||
|
||||
if len(self.animation_queue) > 0:
|
||||
current_animation_action = self.animation_queue.pop(0)
|
||||
print("update action is: " + current_animation_action.get('type'))
|
||||
#print("update action is: " + current_animation_action.get('type'))
|
||||
|
||||
|
||||
# Render the next frame in the queue
|
||||
|
@ -248,7 +250,7 @@ class RenderingLayer:
|
|||
new_image = generate_image_from_point_array(current_animation_action.get('point_array'), 128, 32)
|
||||
|
||||
self.current_point_array = current_animation_action.get('point_array')
|
||||
print("image generated")
|
||||
#print("image generated")
|
||||
|
||||
elif current_animation_action.get('type') == "transition":
|
||||
|
||||
|
@ -321,15 +323,20 @@ class RenderingLayer:
|
|||
else:
|
||||
print("unknown action: ", current_animation_action)
|
||||
|
||||
print("setting image to canvas")
|
||||
offscreen_canvas = matrix.CreateFrameCanvas()
|
||||
#print("setting image to canvas")
|
||||
offscreen_canvas.SetImage(new_image, unsafe=False)
|
||||
print("pushing image to matrix")
|
||||
#print("pushing image to matrix")
|
||||
matrix.SwapOnVSync(offscreen_canvas)
|
||||
print("pushing image done")
|
||||
#print("pushing image done")
|
||||
|
||||
# Save the image to a file with the desired format and file name
|
||||
# new_image.save("output/frameNumber"+str(frameCount)+".png")
|
||||
else:
|
||||
#print("buffer empty")
|
||||
if self.current_animation.get('repeat', False):
|
||||
#print("repeating")
|
||||
self.play_animation(self.current_animation)
|
||||
|
||||
frameCount += 1
|
||||
# new_image.save("output/frameNumber"+str(frameCount)+".png")
|
||||
|
||||
|
|
|
@ -43,6 +43,9 @@ animations:
|
|||
- type: transition
|
||||
to_file: eyesClosed_neutral.png
|
||||
duration: 10
|
||||
- type: image
|
||||
source_file: eyesClosed_neutral.png
|
||||
duration: 1
|
||||
|
||||
- name: set confusion
|
||||
description: Animation to be confused
|
||||
|
@ -56,6 +59,9 @@ animations:
|
|||
- type: transition
|
||||
to_file: dizzyFace.png
|
||||
duration: 10
|
||||
- type: image
|
||||
source_file: dizzyFace.png
|
||||
duration: 1
|
||||
|
||||
- name: set angry
|
||||
description: Animation to be confused
|
||||
|
@ -69,6 +75,9 @@ animations:
|
|||
- type: transition
|
||||
to_file: angryFace.png
|
||||
duration: 10
|
||||
- type: image
|
||||
source_file: angryFace.png
|
||||
duration: 1
|
||||
|
||||
- name: set love
|
||||
description: Animation for love eyes
|
||||
|
@ -82,11 +91,14 @@ animations:
|
|||
- type: transition
|
||||
to_file: loveFace.png
|
||||
duration: 10
|
||||
- type: image
|
||||
source_file: loveFace.png
|
||||
duration: 1
|
||||
|
||||
- name: reset to continuous blink
|
||||
description: Animation for blinking
|
||||
loop_count: 0
|
||||
|
||||
repeat: true
|
||||
trigger: Butn_0005_0001
|
||||
|
||||
overrideable: true
|
||||
|
@ -138,6 +150,10 @@ animations:
|
|||
overrideable: true # blink can be interupted at any time
|
||||
|
||||
graphics:
|
||||
- type: image # hold eye closed
|
||||
source_file: neutral.png
|
||||
duration: 40
|
||||
|
||||
- type: transition # close the eye from whatever the current state
|
||||
to_file: eyesClosed_neutral.png
|
||||
duration: 6
|
||||
|
|
Loading…
Reference in a new issue