Animation problem

dariengs

Member
Licensed User
Longtime User
Hi all - I'm trying to write a program that moves a panel (which I've initialised elsewhere), then waits for the animation to complete before continuing. Currently I've got something like this:

B4X:
Sub DropPanel
Dim balldrop as Animation
balldrop.InitializeTranslate("Animation", 0,0,0,100)  
balldrop.duration = 1000
balldrop.Start(Panel1)   
animationcomplete = False
Do While animationcomplete = False
Loop
End Sub

Sub Animation_AnimationEnd
animationcomplete = True
End Sub
For some reason my code never exits the loop. animationcomplete is a global Boolean variable, so that shouldn't be the problem. Can anyone help?
 

djpero

Member
Licensed User
Longtime User
Do you must to use loop?

Why not resume code in the AnimationEnd Sub?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This code should do it:
B4X:
Sub Globals
    Dim pnlTest, pnlHide As Panel
    Dim btnAnim As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    btnAnim.Initialize("btnAnim")
    Activity.AddView(btnAnim, 10dip, 10dip, 100dip, 60dip)
    btnAnim.Text = "Anim"


    pnlTest.Initialize("pnlTest")
    Activity.AddView(pnlTest, 0, 20%y, 100%x, 70%y)
    pnlTest.Color = Colors.Red

    pnlHide.Initialize("pnlHide")
    Activity.AddView(pnlHide, 0, 0, 100%x, 100%y)
    pnlHide.Color = Colors.Transparent
    pnlHide.Visible = False
End Sub

Sub btnAnim_Click
    Dim balldrop As Animation
    balldrop.InitializeTranslate("Animation", 0,0,0,100)  
    balldrop.duration = 1000
    pnlHide.Visible = True
    balldrop.Start(pnlTest)    
End Sub

Sub Animation_AnimationEnd
    pnlHide.Visible = False
End Sub

Sub pnlHide_Click
    
End Sub
The pnlHide Panel is visible only during the animation and covers the whole screen. The empty pnlHide_Click event caotures the other events.

Best regards.
 
Upvote 0

dariengs

Member
Licensed User
Longtime User
Thanks again Klaus, but I'm afraid that's not quite what I'm trying to do. I want execution to pause entirely until the animation has completed:
B4X:
Sub btnAnim_Click
    Dim balldrop As Animation
    balldrop.InitializeTranslate("Animation", 0,0,0,100)  
    balldrop.duration = 1000
    pnlHide.Visible = True
    balldrop.Start(pnlTest)   
' I really want some magic code to go here
   Msgbox("This should appear only after the animation has completed","Please help!")
End Sub

Thanks also to djpero, but the thing is I'm going round a loop and I simply want to delay starting the next cycle until the animation at the end of the current cycle has completed. So I think moving code into the _AnimationEnd handler would make things messy (though there may well be a clever way of doing it I just haven't spotted yet...)!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I want execution to pause entirely until the animation has completed:
What code execution do you want to avoid during the animation ?
Basic4Android is event driven !
In your example code there is no other code in the routine to execute.
The code example I sent in my previous post avoids all user event ececutions before the animation is finished.

Best regards.
 
Upvote 0

dariengs

Member
Licensed User
Longtime User
It's not user events I want to suspend but program flow. I didn't post my program as it is full of irrelevant functions etc. but basically it is a loop which looks for a view that meets a certain criterion, animates it if found, then repeats. If I let it run at its own pace the program code gets way ahead of the animation. But if I create a loop as in my original post, it seems the _AnimationEnd event is missed...
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Why not moving the rest of your code (the part after the ani) at a sub executed from inside your animationEnd sub?
 
Upvote 0

dariengs

Member
Licensed User
Longtime User
Thanks for the link, Informatix! - That tutorial included an approach I hadn't thought of, namely watching the system time until the Duration of the animation has passed. Now all is well.
 
Upvote 0
Top