Android Question Wanting to move bitmap along spiral path

Scotter

Active Member
Licensed User
So I've learned how to make a bunch of bitmaps fly out of the center of the screen using the SetLayoutAnimated method and a timer.

What I'd like to do next is move a bitmap along a spiral path starting from the center of the screen. Any ideas on how to accomplish this without using thousands of SetLayoutAnimated method in a loop?

Thanks!
 

Scotter

Active Member
Licensed User
use sin & cos to make a circular movement then increase the radius variable.
Thanks! I believe I have the math down.
What I need is ideas on how best to use B4A methods to utilize the math functions.
 

sorex

Expert
Licensed User
here's an example for B4J

B4X:
Sub Process_Globals
    Private fx As JFX
    Dim l As Label
 Dim s As Float
 Dim r As Float
    Dim cx,cy As Int
    Dim t As Timer
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    Form1.Show
    l.Initialize("")
    l.Text="x"
    Form1.RootPane.AddNode(l,0,0,10,10)
    cx=Form1.Width/2
    cy=Form1.Height/2
    t.Initialize("update",1000/60)
    t.Enabled=True
End Sub

Sub update_Tick
    r=r+.3
    s=s+.1
    l.Left=cx+Sin(s)*r
    l.Top=cy+Cos(s)*r
End Sub
 
Last edited:

Scotter

Active Member
Licensed User
here's an example for B4J
B4X:
...
THANK YOU!
I'm guessing what you are doing is putting a bitmap on a form and then using the timer to move that form around.
I'll translate this into B4A, which I don't think will be difficult.
MUCH APPRECIATION!
 

sorex

Expert
Licensed User
I move a label with "x" in it around inside the form (B4J 'activity') with the center as base location (sin/cos is -0.xxx to 0.xxx)

if you comment the r=r+ line you'll have a pure circular movement (if you give r a value first)
 

Scotter

Active Member
Licensed User
Hey @sorex -
The following code causes my bitmap to start in the center small (yes that is what I want) but it then moves diagonal down toward the bottom right corner as it grows.
Ideas?
B4X:
Private Sub animaSpiralTimer_Tick
    If imvSpiralHeart.Height>=imvBiggestTestFor Then
        imvSpiralHeart.Visible=False
        imvSpiralHeart.Enabled=False
        animaLinearTimer.Enabled = False
    Else
        spiral_r = spiral_r + 0.3
        spiral_s = spiral_s + 0.1
        imvHeartWidth = imvHeartWidth + 10dip
        imvHeartHeight = imvHeartHeight + 10dip
        imvSpiralHeart.left = spiral_x + Sin(spiral_s) * spiral_r
        imvSpiralHeart.top = spiral_y + Cos(spiral_s) * spiral_r
        imvSpiralHeart.Width=imvHeartWidth
        imvSpiralHeart.Height=imvHeartHeight
    End If
End Sub
 

sorex

Expert
Licensed User
you should substract half the image width and height to have it centered right but that's not related to the problem you describe.

can you upload the entire code?
 

Scotter

Active Member
Licensed User
Thanks. I appreciate you wanting to help! There is no more code that is relevant.
 
Top