Android Question array of bitmaps inverted-ish

Scotter

Active Member
Licensed User
EDIT: SOLVED! Added this line of code:
B4X:
imvHearts(i).Gravity=Gravity.FILL

Hi -
I've created my first animation, yay, to glitz-up a bit this game.
The first "flying heart" works great. I created the ImageView in the designer and then referenced it from code.
Then I decided I wanted 9 more hearts that fly in random directions from the center of the screen.
I thought I'd control AND create them programmatically.
They animate (move in distance and change in size) exactly as I wanted.
BUT they look "sort of" inverted.
Wanting to know what I'm missing.
Here's the APK if you want to see the behavior: https://ClearSay.net/files/p2e-193.apk
TAP BLUE "SHUFFLE & START" AT BOTTOM.
TO SEE THE ANIMATION AGAIN, TAP ANYWHERE ON THE MAIN YELLOW PANEL IN MIDDLE
Here's the relevant code:
B4X:
Private Sub initAnimaObjects
    Dim iLeft As Float
    Dim iTop As Float
    Dim iWidth As Float
    Dim iHeight As Float

    'this is the "primary heart" that was set up in designer:
    imvHeart.SendToBack
    imvHeart.Visible = False
    imvBiggest=Activity.Width
    imvBiggestTest=Activity.Width
 
    'multi-images set up programmatically
    'THESE BELOW ARE SHOWING UP ON SCREEN "SORT OF" INVERTED. PLEASE SEE THE APK
    'TAP BLUE "SHUFFLE & START" AT BOTTOM.
    'TO SEE THE ANIMATION AGAIN, TAP ANYWHERE ON THE MAIN YELLOW PANEL IN MIDDLE
    For i = 0 To 8
        Dim bmpImage As Bitmap
        bmpImage.Initialize(File.DirAssets,"heart.png")
        imvHearts(i).Initialize("imvHearts")
        imvHearts(i).Tag=i
        imvHearts(i).Bitmap=bmpImage
        iLeft = Activity.Width/2
        iTop = Activity.Height/2
        iWidth = 0dip
        iHeight = 0dip
        Activity.AddView(imvHearts(i),iLeft,iTop,iWidth,iHeight)
    Next
End Sub

Private Sub AnimateTheHeart
    Dim iStartWidth As Float = 0
    imvHeartWidth=0dip
    imvHeartHeight=0dip
    imvHeartLeft = (PanelBehindTabs.Width - iStartWidth)/2
    imvHeartTop = (PanelBehindTabs.Height+Panel1Title.Height)
    imvHeart.SetLayout(imvHeartLeft, imvHeartTop, imvHeartWidth, imvHeartHeight)
    imvHeart.BringToFront
    imvHeart.Visible = True
    iFinalLeftPosition = (PanelBehindTabs.Width-imvBiggest)/2
    imvHeartTop = (PanelBehindTabs.Height+Panel1Title.Height-imvBiggest)/2
    imvHeartTop = (Activity.Height-imvBiggest)/2
    imvHeart.SetLayoutAnimated(600,iFinalLeftPosition,imvHeartTop,imvBiggest,imvBiggest)
 
    'animate the multi-hearts:
    Dim iLeft As Float
    Dim iTop As Float
    Dim iWidth As Float
    Dim iHeight As Float

    Dim iLeftDest As Float
    Dim iTopDest As Float
    Dim iWidthDest As Float
    Dim iHeightDest As Float
    Dim iRndSize As Float
 
    iLeft = Activity.Width/2
    iTop = Activity.Height/2

    For i = 0 To 8
        iRndSize = DipToCurrent(Floor(Rnd(30,255)-30))
        iWidthDest = iRndSize
        iHeightDest = iRndSize
        iHeartsBiggest(i) = iRndSize
        iLeftDest = Activity.Width/2
        iTopDest = Activity.Height/2
        iWidth = 0dip
        iHeight = 0dip
        imvHearts(i).SetLayout(iLeft,iTop,iWidth,iHeight)
        imvHearts(i).BringToFront
        imvHearts(i).Visible=True
        iLeftDest = Floor(Rnd(0,Activity.Width))
        iTopDest = Floor(Rnd(0,Activity.Height))
        imvHearts(i).SetLayoutAnimated(600,iLeftDest,iTopDest,iWidthDest,iHeightDest)
    Next

    'start timer
    AnimaTimer.Initialize("AnimaTimer",900)
    AnimaTimer.Enabled = True
End Sub
Thanks!
 
Last edited:

Scotter

Active Member
Licensed User
As I watch the animation over and over, it seems like the images might be clipping each other.
Is there a way to use layers to eliminate this?
Researching that now but happy if someone interrupts my research with a quick fix.
Thanks!
 
Upvote 0

Scotter

Active Member
Licensed User
Solved!
I love how info-packed these forums are!
All I needed to do was add the following code during image initialization:
B4X:
imvHearts(i).Gravity=Gravity.FILL
 
Upvote 0
Top