B4J Question Run optimization

Shay

Well-Known Member
Licensed User
Longtime User
Hi

I have a game using B4Xpages that I am showing some image, you click on it, and it moves to next screen using:
B4XPages.ShowPageAndRemovePreviousPages("page2")
One you click on the answer, it moved back to page1, using same command, you click on next question and it moved you back to page2
so all the game is moving from page1 to 2 and 2 to 1
The game has many images and it crashed due to mem issue so I used this to solve it:
#VirtualMachineArgs: -Xms1048m -Xmx1048m (I see it is consuming 300Mbps of RAM)

now I have issue (probably also before) that when moving between the pages there is a "delay" of ~0.5/1 sec till images appear on the screen (on that time it can show white or gray screen or back window screen) but this does not happens all the time, it usually happens when moving from page1 with many images to page2 with less (moving back is usually ok, but it is not all the time ok)

my questions:
1. Is it correct approach using the B4XPages.ShowPageAndRemovePreviousPages when moving between the pages
2. How can I optimize the game? maybe allocate more ram to it?
3. When game is over and player start it again from the game (play again) issue of delay is getting even worse
4. Do I need to clean/release something else when ending page

Any other suggestion?
If needed I have some movie I can post
 

Shay

Well-Known Member
Licensed User
Longtime User
I am loading most of the images on first page like this (due to other threads I had here)

B4X:
For i=1 To 4
        For x=1 To 8
            Dim iv As ImageView
            iv.Initialize("img")
            img(Counter)= iv
            img(Counter).SetBitmap(xui.LoadBitmap(File.DirAssets, Main.Level &"_row-" & i & "-col-" & x & ".png"))
            Root.AddView(img(Counter), calcY, calcX, Width, Height)
            iv.PreserveRatio = False
            img(Counter).Tag = i & x
            calcY = calcY + Width
            If Counter = 32 Then
                Exit
            Else
                Counter = Counter + 1
            End If
        Next
        calcY = 0dip
        calcX = calcX + Height
    Next

other places where I needed image as native ImageView I used: (mostly on page 2 which has more delay)
ImageView1.SetImage(xui.LoadBitmapResize(File.DirAssets,"cashir2.jpg", ImageView1.Width, ImageView1.Height, True))
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Thanks, it is much better now, anything else?
maybe:
 
Upvote 0
Top