Inserting Text Object Above Animation

Find quick help here to get you started with Hollywood
Post Reply
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Inserting Text Object Above Animation

Post 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?
Development System : Imac G5, MorphOs 3.19
User avatar
emeck
Posts: 191
Joined: Fri Apr 03, 2015 3:17 pm

Re: Inserting Text Object Above Animation

Post 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)
PowerBook 5.8 MorphOS 3.18
Mac Mini MorphOS 3.18
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Inserting Text Object Above Animation

Post 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.
Development System : Imac G5, MorphOs 3.19
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Inserting Text Object Above Animation

Post 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.
Development System : Imac G5, MorphOs 3.19
User avatar
emeck
Posts: 191
Joined: Fri Apr 03, 2015 3:17 pm

Re: Inserting Text Object Above Animation

Post 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.
PowerBook 5.8 MorphOS 3.18
Mac Mini MorphOS 3.18
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Inserting Text Object Above Animation

Post 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
Development System : Imac G5, MorphOs 3.19
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Inserting Text Object Above Animation

Post 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.
Development System : Imac G5, MorphOs 3.19
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Inserting Text Object Above Animation

Post 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
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Inserting Text Object Above Animation

Post by oceanarts »

jPV wrote: Tue Jun 11, 2024 10:02 am Hmm... at least your For loop isn't going anywhere
:lol:

I lifted the code directly from the example in the docs, thinking it would magically work somehow. :roll:

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.
Development System : Imac G5, MorphOs 3.19
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Inserting Text Object Above Animation

Post 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.
Development System : Imac G5, MorphOs 3.19
Post Reply