Android Question Wanting to move bitmap along spiral path

Discussion in 'Android Questions' started by Scotter, Jan 9, 2019.

  1. Scotter

    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!
     
  2. sorex

    sorex Expert Licensed User

    use sin & cos to make a circular movement then increase the radius variable.
     
    Scotter likes this.
  3. Scotter

    Scotter Active Member Licensed User

    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.
     
  4. sorex

    sorex Expert Licensed User

    here's an example for B4J

    Code:
    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: Jan 9, 2019
  5. Scotter

    Scotter Active Member Licensed User

    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!
     
  6. sorex

    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 likes this.
  7. Scotter

    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?
    Code:
    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
     
  8. sorex

    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 likes this.
  9. Scotter

    Scotter Active Member Licensed User

    Thanks. I appreciate you wanting to help! There is no more code that is relevant.
     
  10. sorex

    sorex Expert Licensed User

    ok, give me a few minutes
     
  11. sorex

    sorex Expert Licensed User

    I don't know what the effect you want is but you can play with this and the parameters.
     

    Attached Files:

  12. Scotter

    Scotter Active Member Licensed User

    It worked! Thank you!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice