oceanarts wrote: ↑Mon Jun 10, 2024 1:28 am
Now I'm getting somewhere, but now I get a 'Specified animation frame is out of range' error.
Hmm... at least your For loop isn't going anywhere, because it would get a bigger start value (frames = 20 or similar) and smaller ending value (1). You should have it as "For Local k = 1 To frames" for playing it from the beginning to end, or "For Local k = frames To 1 Step -1" to play it from end to beginning.
Then there's something else that I'm not sure if it's a Hollywood bug or something I can't see right away. Why frames number gets value 0 always.. like async draw object wouldn't work correctly with anims now...
But in any case, if everything would work in your code, it would still show the text and play the animation once while blocking the script execution until anim stops. In this case it's useless to use async at all, but just do it with normal
PlayAnim() without async (in your first post the issue was because you first played anim forever and it never got to showing the brush, now it works because you first show the brush and then play the animation).
If your plan was to keep animation playing all the time when you can still do other things in the code, then you must use the async option and handle frame updates frequently, for example, with an Interval.
Here's an example for that:
Code: Select all
@DISPLAY{WIDTH = 1920, HEIGHT = 1080, MODE = "FULLSCREEN", TITLE = "Anim_test", COLOR = #BLACK}
@ANIM 1, "building12_anim.gif"
EnableLayers()
Function p_DrawAnim()
; Function that handles both finite and infinite loops
If AsyncDrawFrame(g_anim_handle) ; if AsyncDrawFrame returns True, the last frame has been drawn and we must clear stuff
ClearInterval(g_anim_ival) ; Stop calling the Interval function
g_anim_ival=Nil ; Clear the variables we made earlier
g_anim_handle=Nil
EndIf
EndFunction
Function p_window()
SetFont(#MONOSPACE, 42)
SetFontStyle(#ANTIALIAS)
SetFontColor(#WHITE)
CreateTextObject(1, "Text To Display...")
InsertLayer(1, #TEXTOBJECT, 1, #CENTER, #CENTER)
; Let's use global variables for handle and inverval id, variables become global if not defined as Local,
; but it doesn't hurt to declare them Global for clarity :)
Global g_anim_handle = PlayAnim (1, 0, 0, {Times = 0, Async = True})
Global g_anim_ival = SetInterval(Nil, p_DrawAnim, 1000 / 25) ; Update anim 25 times per second
EndFunction
EscapeQuit(True)
p_window()
Repeat
WaitEvent
Forever