Bug? SetAlphaAnimated

Douglas Farias

Expert
Licensed User
Longtime User
Hi
I'm trying to convert a game made for android where you use the animation library.
b4j unfortunately does not have the animation library similar to B4a

I'm trying to use the SetAlphaAnimated but it is not working, it works only to 0
when the view is visible true and you want put this visible = false

Test using a timer_tick

Test to set the pane visible = true with animation
psplash2.SetAlphaAnimated(1500,1) 'NOT WORK
psplash2.SetAlphaAnimated(1500,0.9) 'NOT WORK
psplash2.SetAlphaAnimated(500,1.0) 'NOT WORK
psplash2.SetAlphaAnimated(500,1) 'NOT WORK

Test to set the pane visible = false with animation
psplash2.SetAlphaAnimated(1500,0) 'WORKS
psplash2.SetAlphaAnimated(500,0) 'WORKS


I m already tryed use callsub and callsubdelayed but dont work too.

i m tryed too put a visible = true before and later the animation code, but the animation dont works.
i made many tests and really dont works when i want put the view visible = true.

i m using java jdk1.8.0_111

how can i fix this?

there is some other code to do the same fade effect?

many thx
 

Cableguy

Expert
Licensed User
Longtime User
Ola Douglas,

Ao contrario das animaçoes em B4A, no B4J as views (nodes) manteem o estdo na qual terminaram a animaçao.
Ou seja, se fizeres um SetAlphaAnimated(500,0), apos a animaçao a view vai manter-se invisivel, e nao precisas de um Viible=False.
Do mesmo modo, basta um SetAlphaAnimated(500,1) para a view voltar a ficar visivel.

Hi Douglas

Contrary to B4A version animations, The B4J ones retain the last state their finished the animation with.
So, a SetAlphaAnimated(500,0) will render the view invisible even after the animation has ended, no need to set visible=false.
In the same way, a SetAlphaAnimated(500,1) Will render the view visible again.
 

Douglas Farias

Expert
Licensed User
Longtime User
pois é, o problema é o SetAlphaAnimated(500,1), não ta dando o efeito de fadein, e nem colocando o view visible = true, simplesmente esta função não acontece nada na tela.
já ao contrario funciona ok SetAlphaAnimated(500,0), que é para deixar invisível, dá a animação e deixa o view visible = false, tudo ok funcionando.

muito estranho
esto usando esta lib que me salvou.
https://www.b4x.com/android/forum/threads/transitions-and-animations-libraries.43136/#post-460839




it is, the problem is the SetAlphaAnimated (500,1), not ta giving the effect of fadein, and not putting the view visible = true, only this function nothing happens on the screen.
since unlike works ok SetAlphaAnimated (500,0), which is to make invisible, gives the animation and let the view visible = false, everything ok working.

very strange
esto using this lib that saved me.
https://www.b4x.com/android/forum/threads/transitions-and-animations-libraries.43136/#post-460839
 

Cableguy

Expert
Licensed User
Longtime User
Eu estou usando essa mesma tecnica numa app que esta a meio, e garanto que funciona... remove os teus Visible = XXXX

I am using it in a soon to release app, and I asure you it works properly, just remove those Visible=XXX
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

I've tested it with this code and it works properly:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private Pane1 As Pane
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
End Sub

Sub Button1_Action
   Pane1.SetAlphaAnimated(1000, 0.5)
End Sub
 

Douglas Farias

Expert
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

I've tested it with this code and it works properly:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private Pane1 As Pane
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
End Sub

Sub Button1_Action
   Pane1.SetAlphaAnimated(1000, 0.5)
End Sub

THX, but dont works.

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private Pane1 As Pane
    Private Button1 As Button
    Private Button2 As Button
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
End Sub


Sub Button1_MouseClicked (EventData As MouseEvent) 'FADE IN
    Pane1.SetAlphaAnimated(1000, 0.5) 'DONT WORK HERE
End Sub

Sub Button2_MouseClicked (EventData As MouseEvent) 'FADE OUT
    Log("here2")
    Pane1.Visible = True 'FIRST WE SET THIS VISIBLE TRUE, BECAUSE BUTTON 1 DONT WORKS FOR ME
    Pane1.SetAlphaAnimated(1000, 0) 'THIS WORKS FINE
End Sub


only fade out works.


here is the demo used
 

Attachments

  • teste.zip
    88.6 KB · Views: 290

Douglas Farias

Expert
Licensed User
Longtime User
Set the panel's visibility to True (by Designer) and:

B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    Pane1.Alpha = 0 ' <-------
   MainForm.Show
End Sub

many thx

I don't see any bug here. SetAlphaAnimated doesn't change the visible property.
ok now i understand, exist a event to know when a setalphaanimated is finished? or only using a timer?


here is how works
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region

Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private Pane1 As Pane
Private Button1 As Button
Private Button2 As Button
Private tfadeout As Timer
End Sub

Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1")
MainForm.Show
tfadeout.Initialize("tfadeout",1000)
End Sub


Sub Button1_MouseClicked (EventData As MouseEvent)
Pane1.Alpha = 0
Pane1.Visible = True
Pane1.SetAlphaAnimated(1000, 1)
End Sub

Sub Button2_MouseClicked (EventData As MouseEvent)
Pane1.SetAlphaAnimated(1000, 0)
tfadeout.Enabled = True
End Sub

Sub tfadeout_Tick
tfadeout.Enabled = False
Pane1.Visible = False
Log("Closed")
End Sub

thx again
 

Cableguy

Expert
Licensed User
Longtime User
No, you don't get an Anim_Finished event, as this is a simpler animation...
Depending on system latency, you may even sometimes not get an animation at all and get your view go from one state to the other on first run, but every other run will look smooth...
Glad you solved it
 

jmon

Well-Known Member
Licensed User
Longtime User
You have to start a timer with the same timing as your animation to know when the animation is finished:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private Pane1 As Pane
   Private EndAnim as Timer
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show

   EndAnim.initialize("EndAnim", 0)
   EndAnim.enabled = false
End Sub

Sub Button1_Action
   Pane1.SetAlphaAnimated(1000, 0.5)
   EndAnim.interval = 1000
   EndAnim.enabled = true
End Sub

Sub EndAnim_Tick
   EndAnim.enabled = false
   Pane1.Alpha = 0.5
   'Animation is finished do your thing here
End Sub
 

jmon

Well-Known Member
Licensed User
Longtime User
I wrote a quick class that could be improved:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private btn As Button
    Private btn2 As Button
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Main") 'Load the layout file.
    MainForm.Show
   
    Dim Anim As AnimWithNotification
    Anim.Initialize(btn, 2000, 0.0, 1000, Me, "btn") 'start with a delay of 1s
End Sub

Sub btn_Finished
    Log($"btn 1 has finished"$)
    Dim Anim As AnimWithNotification
    Anim.Initialize(btn2, 2000, 0.0, 1000, Me, "btn2")
End Sub

Sub btn2_Finished
    Log($"btn 2 has finished"$)
End Sub

The class "AnimWithNotification"
B4X:
#Event:Finished
#RaisesSynchronousEvents:Finished

Sub Class_Globals
    Private fx As JFX
    Private tmr As Timer
    Private m As Object
    Private e As String
    Private d As Int
    Private a As Double
    Private n As Node
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Control As Node, Duration As Int, Alpha As Double, Delay As Int, Module As Object, EventName As String)
    e = EventName
    m = Module
    d = Duration
    a = Alpha
    n = Control
    If Delay > 0 Then
        Dim tmrDelay As Timer
        tmrDelay.Initialize("tmrDelay", Delay)
        tmrDelay.Enabled = True
    Else
        Start
    End If       
End Sub

Private Sub tmrDelay_Tick
    Dim tmrDelay As Timer = Sender
    tmrDelay.Enabled = False
    Start
End Sub

Private Sub Start
    tmr.Initialize("tmr", d)
    tmr.Enabled = True
    n.SetAlphaAnimated(d, a)   
End Sub

Private Sub tmr_Tick
    tmr.Enabled = False
    If SubExists(m, e & "_Finished") Then
        CallSub(m, e & "_Finished")
    End If
End Sub
Check out the example attached
 

Attachments

  • AnimWithNotification.zip
    1.9 KB · Views: 292
Top