Android Question [SOLVED]Label Animation

harinder

Active Member
Licensed User
Longtime User
Hello..Hope everyone safe in these trying times:)

I am kind of stuck with this animation issue. I have an arrow representing wind as fontawesome in a label. The arrow changes direction as per a user choice as follows:
B4X:
setRotation(label,spn.SelectedItem)
B4X:
Sub setRotation(v As View, Angle As Float)
    Dim jo = v As JavaObject
    jo.RunMethod("setRotation", Array As Object(Angle))
End Sub
It rotates fine. Now, I want to animate it so that it moves in same changed direction certain distance and then back to repeat the animation, to give the wind direction FROM feel.
I tried using Animation library as follows:
B4X:
anim.InitializeTranslate("",0,0,(40*Cos(spn.SelectedItem)),(40*Sin(spn.SelectedItem)))
anim.Duration=1000
anim.Repeatcount=-1
anim.Start(label)
But, the direction of movement is not correct in few directions. Please help.
Rgds..
 

TILogistic

Expert
Licensed User
Longtime User
test:

Smooth rotation

B4X:
'XUI library
Sub setRotation(v As B4XView, Angle As Float)
      v.SetRotationAnimated(1000,Angle)
End Sub
 
Upvote 0

emexes

Expert
Licensed User
Perhaps animate the label WindLabel like:
B4X:
Sub Process_Globals
    Private WindLabel As B4XView
    Private WindFrame As Int
    Private WindTimer As Timer

Sub AppStart (Form1 As Form, Args() As String)
    WindTimer.Initialize("WindTimer", 100)
    WindTimer.Enabled = True

Sub WindTimer_Tick
    WindFrame = (WindFrame + 1) Mod 13    '0..12 spaces before arrows'
    WindLabel.Text = "            ➡ ➡ ➡ ➡ ➡".SubString(12 - WindFrame)
End Sub
and then just rotate the whole animated kit and kaboodle using eg:
B4X:
WindLabel.Rotation = 45    'north-east
 
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
simple demo.

B4J.


note: convert wind coordinates in angle

B4X:
Sub setRotation(v As B4XView, Time As Int, Angle As Float)
    v.SetRotationAnimated(Time,Angle)
End Sub

correction:

press button to see the angle effect
 

Attachments

  • test.zip
    2 KB · Views: 252
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
or use the label and angle effect:

note that views have an initial angle
 

Attachments

  • test2.zip
    2.2 KB · Views: 233
Last edited:
Upvote 0

harinder

Active Member
Licensed User
Longtime User
Thank you very much oparra and emexes for the windtimer solution. Thanks really for your time:)
B4X:
Sub WindTimer_Tick
    WindFrame = (WindFrame + 1) Mod 13    '0..12 spaces before arrows'
    WindLabel.Text = "            ➡ ➡ ➡ ➡ ➡".SubString(12 - WindFrame)
End Sub

I got my animation solution working too, courtesy this one post by Erel(i guess he, like god, is everywhere;)):

So, I realized I made a silly mistake. I used cos/sin instead of cosD/sinD.
cos/sin gives radians, cosD/sinD gives degrees(which is what is required).
Hence, this one now works fine too:
B4X:
    anim.InitializeTranslate("",0,0,(40*CosD(spn.SelectedItem)),(40*SinD(spn.SelectedItem)))
    anim.Duration=1000
    anim.Repeatcount=-1
    anim.Start(label)
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
sorry the solution of the publication, it's from Klaus and ilan

I got my animation solution working too, courtesy this one post by Erel(i guess he, like god, is everywhere;)):

effect scrolling label.


or

 
Upvote 0
Top