Page 1 of 1
Inserting Text Object Above Animation
Posted: Sat Jun 08, 2024 9:50 pm
by oceanarts
Having some trouble inserting a layer above a looping gif animation.
A text object, it won't display.
Code: Select all
Function p_WindowMain()
@ANIM 1, "building12_anim.gif"
CreateTextObject(1, "Text Object Text...")
PlayAnim (1, 0, 0, {Speed = #SLOWSPEED, Times = 0})
InsertLayer(1, #TEXTOBJECT, 1, #CENTER, #CENTER); Isn't working.
EndFunction
What is the correct way to do this?
Re: Inserting Text Object Above Animation
Posted: Sun Jun 09, 2024 12:01 am
by emeck
@oceanarts
You are showing the text in a layer in position 1. To specify the last layer use position 0. Try
Code: Select all
InsertLayer(0, #TEXTOBJECT, 1, #CENTER, #CENTER)
Re: Inserting Text Object Above Animation
Posted: Sun Jun 09, 2024 12:16 am
by oceanarts
That doesn't work unfortunately.
Using layer 1 worked well on static bgpics, which made me think it had something to do with the anim constantly updating the screen, and that it had to be done in a special manner with animations.
Re: Inserting Text Object Above Animation
Posted: Sun Jun 09, 2024 8:28 pm
by oceanarts
Okay, so using your correction:
Code: Select all
InsertLayer(0, #TEXTOBJECT, 1, #CENTER, #CENTER)
And setting the animation to play just once, shows the text when animation finishes. But I want it to loop while displaying the text.
Re: Inserting Text Object Above Animation
Posted: Sun Jun 09, 2024 11:53 pm
by emeck
Try the ASync option for
PlayAnim() and the use
AsyncDrawFrame() function to play the anim asynchronously.
That will display the text right after the animation starts and should work for more than one repetition of the anim.
Re: Inserting Text Object Above Animation
Posted: Mon Jun 10, 2024 12:21 am
by oceanarts
emeck wrote: ↑Sun Jun 09, 2024 11:53 pm
Try the ASync option for
PlayAnim() and the use
AsyncDrawFrame() function to play the anim asynchronously.
That will display the text right after the animation starts and should work for more than one repetition of the anim.
Appreciate you effort. This is waaaay over my tiny head. Can you look at the following code and see what's wrong?
I'm getting a EndFunction without Function error.
Code: Select all
@DISPLAY{WIDTH = 1920, HEIGHT = 1080, MODE = "FULLSCREEN", TITLE = "Anim_test", COLOR = #BLACK}
EnableLayers()
Function p_window()
@ANIM 1, "building12_anim.gif"
SetFont(#MONOSPACE, 42)
SetFontStyle(#ANTIALIAS)
SetFontColor(#WHITE)
CreateTextObject(1, "Text To Display...")
InsertLayer(1, #TEXTOBJECT, 1, #CENTER, #CENTER)
obj = PlayAnim (1, 0, 0, {Speed = #SLOWSPEED, Times = 0, Async = True})
frames = GetAttribute(#ASYNCDRAW, obj, #ATTRNUMFRAMES)
For local k = frames to 1
AsyncDrawFrame(obj, k)
VWait
FinishAsyncDraw(obj)
EndFunction
EscapeQuit(True)
p_window()
Repeat
WaitEvent
Forever
Re: Inserting Text Object Above Animation
Posted: Mon Jun 10, 2024 1:28 am
by oceanarts
Sorry, I forgot to say Next after the last For loop.
Now I'm getting somewhere, but now I get a 'Specified animation frame is out of range' error.
Re: Inserting Text Object Above Animation
Posted: Tue Jun 11, 2024 10:02 am
by jPV
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
Re: Inserting Text Object Above Animation
Posted: Tue Jun 11, 2024 7:38 pm
by oceanarts
jPV wrote: ↑Tue Jun 11, 2024 10:02 am
Hmm... at least your For loop isn't going anywhere
I lifted the code directly from the example in the docs, thinking it would magically work somehow.
Your example worked beautifully once I moved the InsertLayer command to the end of the function.
Thanks! I'll try to understand what's happening in the code, and see if I can use it wisely in other instances.
Re: Inserting Text Object Above Animation
Posted: Tue Jun 11, 2024 8:51 pm
by oceanarts
Couple of problems...
How do I end this thing when exiting the animation?
Also, It seems the SimpleButtons associated with a previous static BGPic is still attached to the animation even though I believe I've hidden that layer with HideLayer. RemoveLayer doesn't do anything either.