How to handle animations?

Find quick help here to get you started with Hollywood
Post Reply
amyren
Posts: 430
Joined: Thu May 02, 2019 11:53 am

How to handle animations?

Post by amyren »

I've been browsing the anim library commands in the help documentation.
There is the BeginAnimStream command that lets you make a new anim file and add frames to it.
And the CreateAnim command which also makes a new anim file from a single brush
But how to add more frames to that anim file later?
Same if I load an animation file with LoadAnim, is there a way to edit (overwrite a frame) or to add new frames from a brush into it?
plouf
Posts: 691
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: How to handle animations?

Post by plouf »

ModifyAnimFrames() can add or remove frames

If you load anim tou need to create a new anim and apppend frame by frame there..
Christos
amyren
Posts: 430
Joined: Thu May 02, 2019 11:53 am

Re: How to handle animations?

Post by amyren »

I did read about ModifyAnimFrames() in the docs.
Although it can expand or shrink the number of frames it does not mention how to put content (eg. a brush) into the new frame you added.
To be honest I have a hard time seeing the point of adding frames to an anim if its just empty frames.
plouf
Posts: 691
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: How to handle animations?

Post by plouf »

i see your point, a function like AnimFrameFromBrush() would make sense to modify existing frames

btw jsut to point that CreateAnim() creates whole anims (all frames) from brush not just a single frame
here an example

Code: Select all

CreateBrush(1,200,20,#GREEN) ; Create a sprite sequence "old style"
SelectBrush(1)
For i=0 To 9
TextOut(i*20+5,5,i)
Next 
EndSelect()

DisplayBrush(1,1,1)          ; see it live how it looks
Wait(100)
Cls(#BLACK)
	
CreateAnim(1,1,20,20,10,10)  ; create an anim from that "tape"
For i=1 To 10
	DisplayAnimFrame(1,1,1,i)   ; lets see it 
	Wait(50)
Next
so you can load frame by frame to a big brush, then create a BeginAnimStream() to save your "brushes" to disk in your order
definitely not convient !
Christos
amyren
Posts: 430
Joined: Thu May 02, 2019 11:53 am

Re: How to handle animations?

Post by amyren »

Similar to my thoughts, I was thinking since you have LoadAnimFrame() it would be nice to have SaveAnimFrame() as well.
Perhaps AnimFrameFromBrush() describes its purpose better.
plouf
Posts: 691
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: How to handle animations?

Post by plouf »

ok... my mistake too even not in anim library there is SelectAnim() which you can select ANY frame (the new blank or existing) and start drawing there
like DisplayBrush()...

so it is possible :)

i modify above example, creating anim, then add a new frame, and draw in new frame

Code: Select all

CreateBrush(1,200,20,#GREEN) ; Create a sprite sequence "old style"
SelectBrush(1)
For i=0 To 9
TextOut(i*20+5,5,i)
Next 
EndSelect()

DisplayBrush(1,1,1)          ; see it live how it looks
Wait(100)
Cls(#BLACK)
	
CreateAnim(1,1,20,20,4,4)  ; create an 4 frame anim from that "tape"
For i=1 To 4
	DisplayAnimFrame(1,1,1,i)   ; lets see it 
	Wait(50)
Next


CreateBrush(2,20,20,#RED)	; lets create a new brush
ModifyAnimFrames(1,1,3)		;add a frame in middle (frame 3 making it a 5 frame anim)
; draw the new brush
SelectAnim(1,3)
DisplayBrush(2,1,1)			; draw than new frame with the RED new brush
EndSelect()

For i=1 To 5
	DisplayAnimFrame(1,1,1,i)   ; lets see our new 5 frame anim
	Wait(50)
Next
Christos
amyren
Posts: 430
Joined: Thu May 02, 2019 11:53 am

Re: How to handle animations?

Post by amyren »

Oh my :)
I've been busy working on a workaround so I made this (messy) code to make a way to handle it.
This example can insert, replace or remove a frame in an anim file.

I will look into that SelectAnim() later. Perhaps it can be used in a similar function and do the same thing as my example with less resources.

Code: Select all

frametowrite = 2
task$ = "insert" ;options are "replace" (default"),"insert" or "remove". 
brushtowrite = 2

;create a brush to insert or replace
CreateBrush(2, 640, 480, #RED)

;Create an example anim file with 7 frames
CreateBrush(1, 640, 480)
SelectBrush(1)
SetFillStyle(#FILLCOLOR)

BeginAnimStream(1, "anim_1.gif", 640, 480)
For Local k = 1 To 7
	Box(50,200, 200, 30, #BLACK)
	TextOut(50, 200, "FRAME NUMBER "..k)
   WriteAnimFrame(1, 1)
Next
FinishAnimStream(1)
EndSelect

;f$ = FileRequest("Select an anim file", {Filters = "gif|avi|iff"})
f$ = "anim_1.gif"
If IsAnim(f$)
	OpenAnim(1, f$)
Else
	SystemRequest("Invalid anim file", "File "..f$.." is not a valid anim file", "OK")
	End
EndIf

animwidth = GetAttribute(#ANIM, 1, #ATTRWIDTH)
animheight = GetAttribute(#ANIM, 1, #ATTRHEIGHT)
animframes = GetAttribute(#ANIM, 1, #ATTRNUMFRAMES)

CloseAnim(1)

Function BrushToAnimFrame(brushid, frameno, f$, msg$)
		If msg$ <> "remove"
			If frameno > animframes Then frameno = animframes+1
		Else
			If frameno > animframes Then frameno = animframes
		EndIf
		
		 ;Create a temporary brush to store the whole anim
		If msg$ = "insert"
			CreateBrush(9, animwidth*(animframes+1), animheight, #WHITE)
		ElseIf msg$ = "remove"
			CreateBrush(9, animwidth*(animframes-1), animheight, #WHITE) 
		Else
			CreateBrush(9, animwidth*(Max(animframes, frameno)), animheight, #WHITE) 
		EndIf
		SelectBrush(9)
		Local addwidth = 0
		For i = 1 To animframes
			LoadAnimFrame(10, i, f$)
			If i = frameno And msg$ = "insert" Then addwidth = 1
			If i = frameno+1 And msg$ = "remove" Then addwidth = -1
			DisplayBrush(10, ((i+addwidth)*animwidth)-animwidth, 0)
		Next
		If msg$ <> "remove" Then DisplayBrush(brushid, (animwidth*frameno)-animwidth, 0)
		EndSelect()
		BeginAnimStream(1, f$, 640, 480)
		For i = 1 To Max(animframes+addwidth, frameno)
			CopyBrush(9, 11)
			If msg$ = "remove" And i = animframes
			Else
				CropBrush(11, (i*animwidth)-animwidth, 0, animwidth, animheight)
				WriteAnimFrame(1, 11)
			EndIf
		Next
		FinishAnimStream(1)
		FreeBrush(9)
		FreeBrush(10)
		FreeBrush(11)
		Return(frameno, Max(animframes+addwidth, frameno))
EndFunction

wrtto, frs = BrushToAnimFrame(brushtowrite, frametowrite, f$, task$); (brush id, frame, anim$)

SystemRequest("Done", "Finished updating anim file\nFrame "..wrtto.." updated.\nFrames in anim: "..frs, "OK")


OpenAnim(1, f$)
animframes = GetAttribute(#ANIM, 1, #ATTRNUMFRAMES)

;show the result
LoadAnim(1, f$)
For i = 1 To animframes
	LoadAnimFrame(1, i, f$)
	DisplayBrush(1, 0 , 0)
	Wait(25)
Next
WaitLeftMouse()
Post Reply