Change 'TO' values on the fly in Animation InitializeTranslate

garryp4

New Member
Licensed User
Longtime User
:sign0104:

Can I change, on the fly, the value of the TO X and/or TO Y value in the Animation library InitializeTranslate command? What I have so far does not work. Any suggestions or better way to do this would be greatly appreciated. Very new to B4A. The goal is to move a graphic of a bubble around a graphic of a bubble level based on values transmitted over bluetooth from a circuit I have built. An stuck on the graphics. This code is based on the Animate tutorial.

Thanks

B4X:
'Activity module
Sub Process_Globals
   
End Sub

Sub Globals
   Dim Button1 As Button
   Dim Button6 As Button
   Dim a6        As Animation
   Dim f_x       As Float
   Dim f_y       As Float
   Dim t_x       As Float
   Dim t_y       As Float
   Dim txt1      As EditText
   Dim txt2    As EditText
   Dim y          As Float   
End Sub 

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")

    f_x = 0             ' From X
   f_y = 0             ' From Y
   t_x = 0             ' Too X
   t_y = 10            ' Too Y
   y = 0               ' Vriable for new y value
   
   Dim animations() As Animation
   a6.InitializeTranslate("Animation", f_x, f_y, t_x, t_y)
   Button6.Tag = a6
   Button1.Tag = "b1"
   animations = Array As Animation(a6)
   For i = 0 To animations.Length - 1
      animations(i).Duration = 1000
   Next
End Sub

Sub Animation_AnimationEnd
   If Sender = a6 Then
     txt1.Text = "fx="&f_x & "  fy="&f_y & "  tx="&t_x & "  ty="&t_y & "  b6="&Button6.Top
               ' Message to verify if Y changed or not
     f_x = t_x
     f_y = t_y
     t_x = t_x
     Button6.Top = Button6.Top + y
     txt2.Text = "fx="&f_x & "  fy="&f_y & "  tx="&t_x & "  ty="&t_y & "  b6="&Button6.top
   End If
End Sub

Sub Button_Click
   If Button1.Tag = a6 Then
     y = 50
    Else
     y = 10
   End If
   t_y = y
   'a6.InitializeTranslate("Animation", f_x, f_y, t_x, t_y) ' Stopped the PNG moving smoothly
   a6.Start(Button6)
End Sub
 

imakebeer

New Member
Licensed User
Longtime User
Thanks for the reply. In the following code

B4X:
Sub Button_Click
    If Button1.Tag = a6 Then
      y = 50
     Else
      y = 10
    End If
    t_y = y
    'a6.InitializeTranslate("Animation", f_x, f_y, t_x, t_y) ' Stopped the PNG moving smoothly
    a6.Start(Button6)
End Sub

I did try to initialize it again but the animation would not 'flow' to the 'TO' location but would immediately go there, so the line is commented out. I would like a smooth transition for a natural effect. Is there a way to do this?

Thanks a lot for your time
 
Upvote 0

garryp4

New Member
Licensed User
Longtime User
Informatix - Thank you for the reply. I did as you suggested and used Bing translate to view you tutorial. However I could not get the attached coded to compile. Probably my :sign0104:ness.

The ginger code errors out at line 32.
B4X:
Dim r As Reflector

The puzzle code errors at line 19
B4X:
Dim BP As BitmapPlus

My first guess is I just do not know which library's to check, but that is a guess. Any help is greatly appreciated.

Thanks
 
Upvote 0
Top