Need help optimizing bitmap code to avoid out of memory on S3

uswin4224

Member
Licensed User
Longtime User
Hi everyone,

I really need some advice regarding my code on livewallpaper created using basic4android here. Actually this code is working quite fine on medium-smaller device, but when this livewallpaper is running on New HD device such as Galaxy S3, it tend to crash and show out of memory from bitmap.

I know it must be my code that produce this issue due my code is not efficient enough.
B4X:
Sub Process_Globals
   Dim lwm As LWManager
   Dim lwe As LWEngine
   Dim airpushads As MESAirpushV5   

   
   Dim width As Int 
   Dim height As Int
   Dim x, y, vx, vy As Int
   Dim initialized As Boolean: initialized = False
   Dim boxSize As Int
   
   Dim bgmedium As Bitmap
   Dim bgsmall As Bitmap
   Dim bgbig As Bitmap
   
   Dim backgroundColor As Int
   
   Dim starbig As Bitmap
   Dim starbig2 As Bitmap
   Dim starbig3 As Bitmap
   Dim starbig4 As Bitmap
   Dim starbig5 As Bitmap
   Dim starbig6 As Bitmap
   Dim starbig7 As Bitmap
   Dim starbig8 As Bitmap
   Dim starbig9 As Bitmap
   Dim starbig10 As Bitmap
   
   Dim reccls As Rect  ' Screen Clear Rectangle

   Dim bubblesrnd(7) As Bitmap
   Dim rectbubblernd(7) As Rect
   
   Dim bubbledynamic(7) As Bitmap
   Dim bubbledynamicx(7) As Double
   Dim bubbledynamicy(7) As Double
   Dim bubbledynamicrect(7) As Rect
   
   Dim AngleStep As Float      
   getrotatespeed
'   AngleStep = 0.05
   Dim xyinit As Boolean: initialized = False
   Dim getdir As String
   Dim getspd As String
   Dim getitrc As String
   Dim getpat As String
   Dim getvisible As String
   Dim getrotspd As String
                  
   Dim Angle As Float               : Angle = -AngleStep
   
   
   'Initialize awal sebelum ada perubahan di seting jumlah item
   Dim getnum As Int
   getnumber
   Dim bubblesrndshow(getnum) As Bitmap
   Dim rectbubblerndshow(getnum) As Rect
   
   Dim bubblexrnd(getnum) As Double
   Dim bubbleyrnd(getnum) As Double
      
   Dim MP As MediaPlayer
   
   'Ok lets store animated sparkles the list
   Dim bmpbs As Bitmap ' ground
   Dim anim As List
   Dim animindex As Int
   animindex=0
   
End Sub

Sub Service_Create
   InitializeEngine
'   airpushads.initialise
'   airpushads.startPush("false")
End Sub

Sub Service_Start (StartingIntent As Intent)
'   airpushads.startSmartWall
End Sub

Sub Service_Destroy
   Dim Obj1 As Reflector
   Dim Obj2 As Reflector
   Dim Obj3 As Reflector
   Dim Obj4 As Reflector
   Dim Obj5 As Reflector
   Dim Obj6 As Reflector
   Dim Obj7 As Reflector
'   Dim Obj8(getnum) As Reflector
   Dim Obj9(7) As Reflector
   Dim Obj10(7) As Reflector   
   Dim Obj11 As Reflector
   Dim Obj12 As Reflector
   Dim Obj13 As Reflector
   Dim Obj14 As Reflector
   Dim Obj15 As Reflector
   Dim Obj16 As Reflector
   Dim Obj17 As Reflector
   
   Obj1.Target = bgsmall ' bmp is the unwanted Bitmap
   Obj1.RunMethod("recycle")
   
   Obj2.Target = bgmedium ' bmp is the unwanted Bitmap
   Obj2.RunMethod("recycle")
   
   Obj3.Target = bgbig ' bmp is the unwanted Bitmap
   Obj3.RunMethod("recycle")
   
   Obj4.Target = starbig ' bmp is the unwanted Bitmap
   Obj4.RunMethod("recycle")
   
   Obj5.Target = starbig2 ' bmp is the unwanted Bitmap
   Obj5.RunMethod("recycle")
   
   Obj6.Target = starbig3 ' bmp is the unwanted Bitmap
   Obj6.RunMethod("recycle")
   
   Obj11.Target = starbig4 ' bmp is the unwanted Bitmap
   Obj11.RunMethod("recycle")
   
   Obj12.Target = starbig5 ' bmp is the unwanted Bitmap
   Obj12.RunMethod("recycle")
   
   Obj13.Target = starbig6 ' bmp is the unwanted Bitmap
   Obj13.RunMethod("recycle")
   
   Obj14.Target = starbig7 ' bmp is the unwanted Bitmap
   Obj14.RunMethod("recycle")
   
   Obj15.Target = starbig8 ' bmp is the unwanted Bitmap
   Obj15.RunMethod("recycle")
   
   Obj16.Target = starbig9 ' bmp is the unwanted Bitmap
   Obj16.RunMethod("recycle")
   
   Obj17.Target = starbig10 ' bmp is the unwanted Bitmap
   Obj17.RunMethod("recycle")
      
   Obj7.Target = bmpbs ' bmp is the unwanted Bitmap
   Obj7.RunMethod("recycle")

'   For i=0 To getnum-1
'      Obj8(i).Target = bubblesrndshow(i)' bmp is the unwanted Bitmap
'      Obj8(i).RunMethod("recycle")
'   Next
'   
   For i=0 To 6
      Obj9(i).Target = bubblesrnd(i)' bmp is the unwanted Bitmap
      Obj10(i).Target = bubbledynamic(i)' bmp is the unwanted Bitmap
      Obj9(i).RunMethod("recycle")
      Obj10(i).RunMethod("recycle")
   Next
   
'   Log("i:"&i)
   
End Sub

Sub lwm_SizeChanged (Engine As LWEngine)
   DrawBackground(Engine)
End Sub

Sub lwm_OffsetChanged (Engine As LWEngine)

End Sub

Sub DrawBackground (Engine As LWEngine)   
   getnumber
   getheartvisible
   If Engine.ScreenWidth>Engine.ScreenHeight Then
      FullRefreshLandscape(Engine)
   Else
      FullRefreshPortrait(Engine)
   End If
   If getvisible ="False" Then
      'set direction in drawing
      If getdir == 0 Then              'move bubble to left
         MoveLeft(Engine)
      Else If getdir == 1 Then      'move bubble to up         
         MoveUp(Engine)
      Else If getdir == 2 Then       'move bubble to right
         MoveRight(Engine)
      Else If getdir == 3 Then      'move bubble to down
         MoveDown(Engine)
      End If
   End If
   reccls.Initialize(0,0,Engine.ScreenWidth,Engine.ScreenHeight)
   Engine.Refresh(reccls)
End Sub

Sub lwm_VisibilityChanged (Engine As LWEngine, Visible As Boolean)
   If Visible Then
      DrawBackground(Engine)
   End If
End Sub

Sub lwm_Tick(Engine As LWEngine)
   DrawBackground(Engine)
End Sub

'Fungsi untuk menginisiasi engine lwp awal termasuk itemnya
Sub InitializeEngine
   lwm.Initialize("lwm", True)
   
   'Initialize berikutnya looping setelah ada perubahan di seting jumlah item
   Dim getnum As Int
   
   getnumber
   getspeed
   getdirection
   getdisableinteraction
   getrotatespeed
   
   boxSize=50
   
   MP.Initialize
   MP.Load(File.DirAssets, "bubble.wav")
   MP.SetVolume(0.5,0.5)
   
   Dim bubblesrndshow(getnum) As Bitmap
   Dim rectbubblerndshow(getnum) As Rect
   
   Dim bubblexrnd(getnum) As Double
   Dim bubbleyrnd(getnum) As Double
   
   bgsmall.Initialize(File.DirAssets, "small.jpg")
   bgmedium.Initialize(File.DirAssets, "medium.jpg")
   bgbig.Initialize(File.DirAssets, "big.jpg")
   
   starbig.Initialize(File.DirAssets, "bigstar.png")
   starbig2.Initialize(File.DirAssets, "bigstar2.png")
   starbig3.Initialize(File.DirAssets, "bigstar3.png")
   starbig4.Initialize(File.DirAssets, "bigstar4.png")
   starbig5.Initialize(File.DirAssets, "bigstar5.png")
   starbig6.Initialize(File.DirAssets, "bigstar6.png")
   starbig7.Initialize(File.DirAssets, "bigstar7.png")
   starbig8.Initialize(File.DirAssets, "bigstar8.png")
   starbig9.Initialize(File.DirAssets, "bigstar9.png")
   starbig10.Initialize(File.DirAssets, "bigstar10.png")
   
   lwm.StartTicking(33) 'Start the wallpaper timer (refresh every 5 milliseconds).
   '======================================================
   
   bmpbs.Initialize(File.DirAssets,"spark_0.png") 'BAmiga sector 1 animated ground..
   ' And initialize anim list emty
   anim.Initialize
   ' store boring 51 pics to the list .... all work to show how to anim gifs :)
   anim.AddAll(Array As String("spark_0.png", "spark_1.png", "spark_2.png", "spark_3.png", "spark_4.png", "spark_5.png", _
   "spark_6.png", "spark_7.png", "spark_8.png", "spark_9.png", "spark_10.png", "spark_11.png", "spark_12.png", "spark_13.png", _
   "spark_14.png", "spark_15.png", "spark_16.png", "spark_17.png", "spark_18.png", "spark_19.png", "spark_20.png", "spark_21.png", _ 
   "spark_22.png", "spark_23.png", "spark_24.png", "spark_25.png", "spark_26.png", "spark_27.png", "spark_28.png", "spark_29.png"))
   
   'Initialize all used item bubbles 
   
   bubblesrnd(0).Initialize(File.DirAssets, "10.png")
   bubblesrnd(1).Initialize(File.DirAssets, "20.png")
   bubblesrnd(2).Initialize(File.DirAssets, "30.png")
   bubblesrnd(3).Initialize(File.DirAssets, "40.png")
   bubblesrnd(4).Initialize(File.DirAssets, "402.png")
   bubblesrnd(5).Initialize(File.DirAssets, "50.png")
   bubblesrnd(6).Initialize(File.DirAssets, "100.png")
   
   bubbledynamic(0)=bubblesrnd(0)
   bubbledynamic(1)=bubblesrnd(1)
   bubbledynamic(2)=bubblesrnd(2)
   bubbledynamic(3)=bubblesrnd(3)
   bubbledynamic(4)=bubblesrnd(4)
   bubbledynamic(5)=bubblesrnd(5)
   bubbledynamic(6)=bubblesrnd(6)
   
   rectbubblernd(0).Initialize(bubblexrnd(0), bubbleyrnd(0), bubblexrnd(0)+10, bubbleyrnd(0)+10)
   rectbubblernd(1).Initialize(bubblexrnd(1), bubbleyrnd(1), bubblexrnd(1)+20, bubbleyrnd(1)+20)
   rectbubblernd(2).Initialize(bubblexrnd(2), bubbleyrnd(2), bubblexrnd(2)+30, bubbleyrnd(2)+30)
   rectbubblernd(3).Initialize(bubblexrnd(3), bubbleyrnd(3), bubblexrnd(3)+40, bubbleyrnd(3)+40)
   rectbubblernd(4).Initialize(bubblexrnd(4), bubbleyrnd(4), bubblexrnd(4)+40, bubbleyrnd(4)+40)
   rectbubblernd(5).Initialize(bubblexrnd(5), bubbleyrnd(5), bubblexrnd(5)+50, bubbleyrnd(5)+50)
   rectbubblernd(6).Initialize(bubblexrnd(6), bubbleyrnd(6), bubblexrnd(6)+100, bubbleyrnd(6)+100)
   
   bubbledynamicrect(0) = rectbubblernd(0)
   bubbledynamicrect(1) = rectbubblernd(1)
   bubbledynamicrect(2) = rectbubblernd(2)
   bubbledynamicrect(3) = rectbubblernd(3)
   bubbledynamicrect(4) = rectbubblernd(4)
   bubbledynamicrect(5) = rectbubblernd(5)
   bubbledynamicrect(6) = rectbubblernd(6)
   
   For i=0 To getnum-1
      bubblesrndshow(i)=bubblesrnd(Rnd(0,7)) 'random dari 1-7
      'rectbubblerndshow(i)=rectbubblernd(Rnd(0,6))
      If bubblesrndshow(i) = bubblesrnd(0) Then
         rectbubblerndshow(i) = rectbubblernd(0)
      Else If bubblesrndshow(i) = bubblesrnd(1) Then
         rectbubblerndshow(i) = rectbubblernd(1)
      Else If bubblesrndshow(i) = bubblesrnd(2) Then
         rectbubblerndshow(i) = rectbubblernd(2)
      Else If bubblesrndshow(i) = bubblesrnd(3) Then
         rectbubblerndshow(i) = rectbubblernd(3)
      Else If bubblesrndshow(i) = bubblesrnd(4) Then
         rectbubblerndshow(i) = rectbubblernd(4)
      Else If bubblesrndshow(i) = bubblesrnd(5) Then
         rectbubblerndshow(i) = rectbubblernd(5)
      Else If bubblesrndshow(i) = bubblesrnd(6) Then
         rectbubblerndshow(i) = rectbubblernd(6)
      End If
   Next
End Sub

Sub lwm_Touch (Engine As LWEngine, Action As Int, tx As Float, ty As Float)

   If getitrc =="False" Then
   For i=0 To getnum-1
            If Action <> 0 Then Return '0 is the value of Activity.ACTION_DOWN
               If tx > bubblexrnd(i) - boxSize AND tx < bubblexrnd(i) + boxSize AND _
               ty > bubbleyrnd(i) - boxSize AND ty < bubbleyrnd(i) + boxSize Then
               bubblexrnd(i) = -bubblexrnd(i) 'change the smiley direction if the user pressed on it
               bubbleyrnd(i) = -bubbleyrnd(i)
               MP.Play
            End If
      Next
   For i=0 To bubbledynamic.Length-1
            If Action <> 0 Then Return '0 is the value of Activity.ACTION_DOWN
               If tx > bubbledynamicx(i) - boxSize AND tx < bubbledynamicx(i) + boxSize AND _
               ty > bubbledynamicy(i) - boxSize AND ty < bubbledynamicy(i) + boxSize Then
               bubbledynamicx(i) = -bubbledynamicx(i) 'change the smiley direction if the user pressed on it
               bubbledynamicy(i) = -bubbledynamicy(i)
               MP.Play
            End If
      Next
   End If
End Sub

Sub FullRefreshPortrait(Engine As LWEngine)
   'Refresh background at start
   Dim aRectOffSet_small As Rect
   Dim aRectOffSet_medium As Rect
   Dim aRectOffSet_big As Rect
   Dim aRect As Rect   
   
   Dim starsmallrect As Rect
   Dim starsmallrect_offset As Rect
   Dim starmediumrect As Rect
   Dim starmediumrect_offset As Rect
   Dim starbigrect As Rect
   Dim starbigrect_offset As Rect
   
   'set sparkles
   Dim sparkleRect As Rect
   Dim sparkleRectOffset_small1 As Rect
   Dim sparkleRectOffset_small2 As Rect
   Dim sparkleRectOffset_small3 As Rect
   Dim sparkleRectOffset_small4 As Rect
   Dim sparkleRectOffset_small5 As Rect
   Dim sparkleRectOffset_small6 As Rect
   Dim sparkleRectOffset_small7 As Rect
   Dim sparkleRectOffset_small8 As Rect
   Dim sparkleRectOffset_medium1 As Rect
   Dim sparkleRectOffset_medium2 As Rect
   Dim sparkleRectOffset_medium3 As Rect
   Dim sparkleRectOffset_medium4 As Rect
   Dim sparkleRectOffset_medium5 As Rect
   Dim sparkleRectOffset_medium6 As Rect
   Dim sparkleRectOffset_medium7 As Rect
   Dim sparkleRectOffset_medium8 As Rect
   Dim sparkleRectOffset_big1 As Rect
   Dim sparkleRectOffset_big2 As Rect
   Dim sparkleRectOffset_big3 As Rect
   Dim sparkleRectOffset_big4 As Rect
   Dim sparkleRectOffset_big5 As Rect
   Dim sparkleRectOffset_big6 As Rect
   Dim sparkleRectOffset_big7 As Rect
   Dim sparkleRectOffset_big8 As Rect
   
   getrotatespeed
   If getrotspd = 0 Then AngleStep = 0.05
   If getrotspd = 1 Then AngleStep = 0.30
   If getrotspd = 2 Then AngleStep = 1.00
   If getrotspd = 3 Then AngleStep = 2.00
   If getrotspd = 4 Then AngleStep = 3.00
   If getrotspd = 5 Then AngleStep = 5.00
   Angle = (Angle+AngleStep) Mod 360
   
   aRectOffSet_small.Initialize(0 + Engine.CurrentOffsetX, 0 , Engine.ScreenWidth + Engine.CurrentOffsetX, bgsmall.height-(bgsmall.height-Engine.ScreenHeight))
   aRectOffSet_medium.Initialize(0 + Engine.CurrentOffsetX, 0 , Engine.ScreenWidth + Engine.CurrentOffsetX, bgmedium.height-(bgmedium.height-Engine.ScreenHeight))
   aRectOffSet_big.Initialize(0 + Engine.CurrentOffsetX, 0 , Engine.ScreenWidth + Engine.CurrentOffsetX, bgbig.height-(bgbig.height-Engine.ScreenHeight))
   
   'DrawBackground (Engine)
   sparkleRect.Initialize(0,0,200,200)
   starsmallrect.Initialize(0,0,250,250)
   starmediumrect.Initialize(0,0,500,500)
   starbigrect.Initialize(0,0,800,800)
   aRect.Initialize(0,0,Engine.ScreenWidth,Engine.ScreenHeight)
   
   'set the sparkles small
   sparkleRectOffset_small1.Initialize((0.1*bgsmall.width)-Engine.CurrentOffsetX, 100 ,((0.1*bgsmall.width)-Engine.CurrentOffsetX)+200, bmpbs.height+100)
   sparkleRectOffset_small2.Initialize((0.3*bgsmall.width)-Engine.CurrentOffsetX, 500 ,((0.3*bgsmall.width)-Engine.CurrentOffsetX)+200, bmpbs.height+500)
   sparkleRectOffset_small3.Initialize((0.4*bgsmall.width)-Engine.CurrentOffsetX, 100 ,((0.4*bgsmall.width)-Engine.CurrentOffsetX)+200, bmpbs.height+100)
   sparkleRectOffset_small4.Initialize((0.5*bgsmall.width)-Engine.CurrentOffsetX, 400 ,((0.5*bgsmall.width)-Engine.CurrentOffsetX)+200, bmpbs.height+400)
   sparkleRectOffset_small5.Initialize((0.7*bgsmall.width)-Engine.CurrentOffsetX, 100 ,((0.7*bgsmall.width)-Engine.CurrentOffsetX)+200, bmpbs.height+100)
   sparkleRectOffset_small6.Initialize((0.7*bgsmall.width)-Engine.CurrentOffsetX, 300 ,((0.7*bgsmall.width)-Engine.CurrentOffsetX)+200, bmpbs.height+300)
   sparkleRectOffset_small7.Initialize((0.1*bgsmall.width)-Engine.CurrentOffsetX, 300 ,((0.1*bgsmall.width)-Engine.CurrentOffsetX)+200, bmpbs.height+300)
   sparkleRectOffset_small8.Initialize((0.7*bgsmall.width)-Engine.CurrentOffsetX, 300 ,((0.7*bgsmall.width)-Engine.CurrentOffsetX)+200, bmpbs.height+300)
      
   'set the sparkles medium
   sparkleRectOffset_medium1.Initialize((0.1*bgmedium.width)-Engine.CurrentOffsetX, 100 ,((0.1*bgmedium.width)-Engine.CurrentOffsetX)+200, bmpbs.height+100)
   sparkleRectOffset_medium2.Initialize((0.3*bgmedium.width)-Engine.CurrentOffsetX, 500 ,((0.3*bgmedium.width)-Engine.CurrentOffsetX)+200, bmpbs.height+500)
   sparkleRectOffset_medium3.Initialize((0.4*bgmedium.width)-Engine.CurrentOffsetX, 100 ,((0.4*bgmedium.width)-Engine.CurrentOffsetX)+200, bmpbs.height+100)
   sparkleRectOffset_medium4.Initialize((0.5*bgmedium.width)-Engine.CurrentOffsetX, 400 ,((0.5*bgmedium.width)-Engine.CurrentOffsetX)+200, bmpbs.height+400)
   sparkleRectOffset_medium5.Initialize((0.7*bgmedium.width)-Engine.CurrentOffsetX, 100 ,((0.7*bgmedium.width)-Engine.CurrentOffsetX)+200, bmpbs.height+100)
   sparkleRectOffset_medium6.Initialize((0.7*bgmedium.width)-Engine.CurrentOffsetX, 600 ,((0.7*bgmedium.width)-Engine.CurrentOffsetX)+200, bmpbs.height+600)
   sparkleRectOffset_medium7.Initialize((0.1*bgmedium.width)-Engine.CurrentOffsetX, 650 ,((0.1*bgmedium.width)-Engine.CurrentOffsetX)+200, bmpbs.height+650)
   sparkleRectOffset_medium8.Initialize((0.7*bgmedium.width)-Engine.CurrentOffsetX, 650 ,((0.7*bgmedium.width)-Engine.CurrentOffsetX)+200, bmpbs.height+650)
   
   'set the sparkles big
   sparkleRectOffset_big1.Initialize((0.1*bgbig.width)-Engine.CurrentOffsetX, 100 ,((0.1*bgbig.width)-Engine.CurrentOffsetX)+200, bmpbs.height+100)
   sparkleRectOffset_big2.Initialize((0.3*bgbig.width)-Engine.CurrentOffsetX, 500 ,((0.3*bgbig.width)-Engine.CurrentOffsetX)+200, bmpbs.height+500)
   sparkleRectOffset_big3.Initialize((0.4*bgbig.width)-Engine.CurrentOffsetX, 100 ,((0.4*bgbig.width)-Engine.CurrentOffsetX)+200, bmpbs.height+100)
   sparkleRectOffset_big4.Initialize((0.5*bgbig.width)-Engine.CurrentOffsetX, 400 ,((0.5*bgbig.width)-Engine.CurrentOffsetX)+200, bmpbs.height+400)
   sparkleRectOffset_big5.Initialize((0.7*bgbig.width)-Engine.CurrentOffsetX, 100 ,((0.7*bgbig.width)-Engine.CurrentOffsetX)+200, bmpbs.height+100)
   sparkleRectOffset_big6.Initialize((0.7*bgbig.width)-Engine.CurrentOffsetX, 600 ,((0.7*bgbig.width)-Engine.CurrentOffsetX)+200, bmpbs.height+600)
   sparkleRectOffset_big7.Initialize((0.03*bgbig.width)-Engine.CurrentOffsetX, 800 ,((0.03*bgbig.width)-Engine.CurrentOffsetX)+200, bmpbs.height+800)
   sparkleRectOffset_big8.Initialize((0.8*bgbig.width)-Engine.CurrentOffsetX, 800 ,((0.8*bgbig.width)-Engine.CurrentOffsetX)+200, bmpbs.height+800)
   
   'set the star rotation
   starsmallrect_offset.Initialize((0.30*bgsmall.width)-Engine.CurrentOffsetX,DipToCurrent(0.2*Engine.ScreenHeight),(((0.30*bgsmall.width))-Engine.CurrentOffsetX)+250, 250+DipToCurrent((0.2*Engine.ScreenHeight)))
   
   starmediumrect_offset.Initialize((0.26*bgmedium.width)-Engine.CurrentOffsetX,DipToCurrent(0.15*Engine.ScreenHeight),(((0.26*bgmedium.width))-Engine.CurrentOffsetX)+500, 500+DipToCurrent((0.15*Engine.ScreenHeight)))

   starbigrect_offset.Initialize((0.25*bgbig.width)-Engine.CurrentOffsetX,DipToCurrent(0.1*Engine.ScreenHeight),(((0.25*bgbig.width))-Engine.CurrentOffsetX)+800, 800+DipToCurrent((0.1*Engine.ScreenHeight)))

   
   'starmediumrect_offset.Initialize((0.2*bgmedium.width)-Engine.CurrentOffsetX, (0.1*bgmedium.height) ,((0.2*bgmedium.width)-Engine.CurrentOffsetX)+700, 700+(0.1*bgmedium.height))
   'starbigrect_offset.Initialize((0.2*bgbig.width)-Engine.CurrentOffsetX,(0.2*bgbig.height) ,((0.2*bgbig.width)-Engine.CurrentOffsetX)+800, 800+(0.2*bgbig.height))
         
'   Log("arecoffset_small : " &aRectOffSet_small)
'   Log("arecoffset_medium : " &starmediumrect_offset)
'   Log("arecoffset_big : " &aRectOffSet_big)
'   Log("arect : " &aRect)   
   
   'Portrait
   If Engine.ScreenWidth <= 320 Then
      Engine.Canvas.DrawBitmap(bgsmall,aRectOffSet_small,aRect)
      getpattern
      If getpat="0" Then Engine.Canvas.DrawBitmapRotated(starbig,Null,starsmallrect_offset,Angle)
      If getpat="1" Then Engine.Canvas.DrawBitmapRotated(starbig2,Null,starsmallrect_offset,Angle)
      If getpat="2" Then Engine.Canvas.DrawBitmapRotated(starbig3,Null,starsmallrect_offset,Angle)
      If getpat="3" Then Engine.Canvas.DrawBitmapRotated(starbig4,Null,starsmallrect_offset,Angle)
      If getpat="4" Then Engine.Canvas.DrawBitmapRotated(starbig5,Null,starsmallrect_offset,Angle)
      If getpat="5" Then Engine.Canvas.DrawBitmapRotated(starbig6,Null,starsmallrect_offset,Angle)
      If getpat="6" Then Engine.Canvas.DrawBitmapRotated(starbig7,Null,starsmallrect_offset,Angle)
      If getpat="7" Then Engine.Canvas.DrawBitmapRotated(starbig8,Null,starsmallrect_offset,Angle)
      If getpat="8" Then Engine.Canvas.DrawBitmapRotated(starbig9,Null,starsmallrect_offset,Angle)
      If getpat="9" Then Engine.Canvas.DrawBitmapRotated(starbig10,Null,starsmallrect_offset,Angle)
      bmpbs.Initialize(File.DirAssets,anim.get(animindex))
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small1) ' ground...
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small2)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small3)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small4)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small5)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small6)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small7)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small8)
      
   Else If Engine.ScreenWidth <= 540 Then
      Engine.Canvas.DrawBitmap(bgmedium,aRectOffSet_medium,aRect)
      getpattern
      If getpat="0" Then Engine.Canvas.DrawBitmapRotated(starbig,Null,starmediumrect_offset,Angle)
      If getpat="1" Then Engine.Canvas.DrawBitmapRotated(starbig2,Null,starmediumrect_offset,Angle)
      If getpat="2" Then Engine.Canvas.DrawBitmapRotated(starbig3,Null,starmediumrect_offset,Angle)
      If getpat="3" Then Engine.Canvas.DrawBitmapRotated(starbig4,Null,starmediumrect_offset,Angle)
      If getpat="4" Then Engine.Canvas.DrawBitmapRotated(starbig5,Null,starmediumrect_offset,Angle)
      If getpat="5" Then Engine.Canvas.DrawBitmapRotated(starbig6,Null,starmediumrect_offset,Angle)
      If getpat="6" Then Engine.Canvas.DrawBitmapRotated(starbig7,Null,starmediumrect_offset,Angle)
      If getpat="7" Then Engine.Canvas.DrawBitmapRotated(starbig8,Null,starmediumrect_offset,Angle)
      If getpat="8" Then Engine.Canvas.DrawBitmapRotated(starbig9,Null,starmediumrect_offset,Angle)
      If getpat="9" Then Engine.Canvas.DrawBitmapRotated(starbig10,Null,starmediumrect_offset,Angle)
      bmpbs.Initialize(File.DirAssets,anim.get(animindex))
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium1) ' ground...
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium2)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium3)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium4)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium5)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium6)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium7)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium8)
      
   Else If Engine.ScreenWidth <= 800 Then
      Engine.Canvas.DrawBitmap(bgbig,aRectOffSet_big,aRect)
      getpattern
      If getpat="0" Then Engine.Canvas.DrawBitmapRotated(starbig,Null,starbigrect_offset,Angle)
      If getpat="1" Then Engine.Canvas.DrawBitmapRotated(starbig2,Null,starbigrect_offset,Angle)
      If getpat="2" Then Engine.Canvas.DrawBitmapRotated(starbig3,Null,starbigrect_offset,Angle)
      If getpat="3" Then Engine.Canvas.DrawBitmapRotated(starbig4,Null,starbigrect_offset,Angle)
      If getpat="4" Then Engine.Canvas.DrawBitmapRotated(starbig5,Null,starbigrect_offset,Angle)
      If getpat="5" Then Engine.Canvas.DrawBitmapRotated(starbig6,Null,starbigrect_offset,Angle)
      If getpat="6" Then Engine.Canvas.DrawBitmapRotated(starbig7,Null,starbigrect_offset,Angle)
      If getpat="7" Then Engine.Canvas.DrawBitmapRotated(starbig8,Null,starbigrect_offset,Angle)
      If getpat="8" Then Engine.Canvas.DrawBitmapRotated(starbig9,Null,starbigrect_offset,Angle)
      If getpat="9" Then Engine.Canvas.DrawBitmapRotated(starbig10,Null,starbigrect_offset,Angle)
      bmpbs.Initialize(File.DirAssets,anim.get(animindex))
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big1) ' ground...
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big2)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big3)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big4)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big5)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big6)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big7)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big8)   
   End If
   animindex=animindex+1      ' increase anim index to show picname+1 
   If animindex>29 Then animindex=0 ' block animindex at 51 coze we have 0+51=52 pics 
End Sub


Sorry, forgot to attached the complete project. Here are the complete project files

Link for attachment :

Download mycrashwallpaper.rar (complete project)
Download crash.rar (crash log and video)

continued on next post ...
 
Last edited:

uswin4224

Member
Licensed User
Longtime User
B4X:
Sub FullRefreshLandscape(Engine As LWEngine)
   'Refresh background at start
   Dim aRectOffSet_small As Rect
   Dim aRectOffSet_medium As Rect
   Dim aRectOffSet_big As Rect
   Dim aRect As Rect   
   
   Dim starsmallrect As Rect
   Dim starsmallrect_offset As Rect
   Dim starmediumrect As Rect
   Dim starmediumrect_offset As Rect
   Dim starbigrect As Rect
   Dim starbigrect_offset As Rect
   
   'set sparkles
   Dim sparkleRect As Rect
   Dim sparkleRectOffset_small1 As Rect
   Dim sparkleRectOffset_small2 As Rect
   Dim sparkleRectOffset_small3 As Rect
   Dim sparkleRectOffset_small4 As Rect
   Dim sparkleRectOffset_small5 As Rect
   Dim sparkleRectOffset_small6 As Rect
   Dim sparkleRectOffset_small7 As Rect
   Dim sparkleRectOffset_small8 As Rect
   Dim sparkleRectOffset_medium1 As Rect
   Dim sparkleRectOffset_medium2 As Rect
   Dim sparkleRectOffset_medium3 As Rect
   Dim sparkleRectOffset_medium4 As Rect
   Dim sparkleRectOffset_medium5 As Rect
   Dim sparkleRectOffset_medium6 As Rect
   Dim sparkleRectOffset_medium7 As Rect
   Dim sparkleRectOffset_medium8 As Rect
   Dim sparkleRectOffset_big1 As Rect
   Dim sparkleRectOffset_big2 As Rect
   Dim sparkleRectOffset_big3 As Rect
   Dim sparkleRectOffset_big4 As Rect
   Dim sparkleRectOffset_big5 As Rect
   Dim sparkleRectOffset_big6 As Rect
   Dim sparkleRectOffset_big7 As Rect
   Dim sparkleRectOffset_big8 As Rect
   
   getrotatespeed
   If getrotspd = 0 Then AngleStep = 0.05
   If getrotspd = 1 Then AngleStep = 0.30
   If getrotspd = 2 Then AngleStep = 0.65
   If getrotspd = 3 Then AngleStep = 0.80
   If getrotspd = 4 Then AngleStep = 1.00
   If getrotspd = 5 Then AngleStep = 5.00
   Angle = (Angle+AngleStep) Mod 360
   
   aRectOffSet_small.Initialize(0.1*bgsmall.width,0, bgsmall.width-(bgsmall.width-Engine.ScreenWidth)+(0.1*bgsmall.width), bgsmall.height-(bgsmall.height-Engine.ScreenHeight))
   aRectOffSet_medium.Initialize(0.1*bgmedium.width,0, bgmedium.width-(bgmedium.width-Engine.ScreenWidth)+(0.1*bgmedium.width), bgmedium.height-(bgmedium.height-Engine.ScreenHeight))
   aRectOffSet_big.Initialize(0.1*bgbig.width,0, bgbig.width-(bgbig.width-Engine.ScreenWidth)+(0.1*bgbig.width), bgbig.height-(bgbig.height-Engine.ScreenHeight))

   'set the star rotation
   starsmallrect_offset.Initialize(DipToCurrent(0.1*Engine.ScreenWidth),DipToCurrent(0.1*Engine.ScreenHeight),(DipToCurrent((0.1*Engine.ScreenWidth)))+250, 250+DipToCurrent((0.1*Engine.ScreenHeight)))
   starmediumrect_offset.Initialize(DipToCurrent(0.15*Engine.ScreenWidth),DipToCurrent(0.1*Engine.ScreenHeight),(DipToCurrent((0.15*Engine.ScreenWidth)))+500, 500+DipToCurrent((0.1*Engine.ScreenHeight)))
   starbigrect_offset.Initialize(DipToCurrent(0.1*Engine.ScreenWidth),DipToCurrent(0.1*Engine.ScreenHeight),(DipToCurrent((0.1*Engine.ScreenWidth)))+800, 800+DipToCurrent((0.1*Engine.ScreenHeight)))

   'set the sparkles small
   sparkleRectOffset_small1.Initialize((0.1*bgsmall.width), 100 ,((0.1*bgsmall.width))+200, bmpbs.height+100)
   sparkleRectOffset_small2.Initialize((0.3*bgsmall.width), 500 ,((0.3*bgsmall.width))+200, bmpbs.height+500)
   sparkleRectOffset_small3.Initialize((0.4*bgsmall.width), 100 ,((0.4*bgsmall.width))+200, bmpbs.height+100)
   sparkleRectOffset_small4.Initialize((0.5*bgsmall.width), 400 ,((0.5*bgsmall.width))+200, bmpbs.height+400)
   sparkleRectOffset_small5.Initialize((0.7*bgsmall.width), 100 ,((0.7*bgsmall.width))+200, bmpbs.height+100)
   sparkleRectOffset_small6.Initialize((0.7*bgsmall.width), 300 ,((0.7*bgsmall.width))+200, bmpbs.height+300)
   sparkleRectOffset_small7.Initialize((0.1*bgsmall.width), 300 ,((0.1*bgsmall.width))+200, bmpbs.height+300)
   sparkleRectOffset_small8.Initialize((0.7*bgsmall.width), 300 ,((0.7*bgsmall.width))+200, bmpbs.height+300)
   
   'set the sparkles medium
   sparkleRectOffset_medium1.Initialize((0.1*bgmedium.width), 100 ,((0.1*bgmedium.width))+200, bmpbs.height+100)
   sparkleRectOffset_medium2.Initialize((0.3*bgmedium.width), 500 ,((0.3*bgmedium.width))+200, bmpbs.height+500)
   sparkleRectOffset_medium3.Initialize((0.4*bgmedium.width), 100 ,((0.4*bgmedium.width))+200, bmpbs.height+100)
   sparkleRectOffset_medium4.Initialize((0.5*bgmedium.width), 400 ,((0.5*bgmedium.width))+200, bmpbs.height+400)
   sparkleRectOffset_medium5.Initialize((0.7*bgmedium.width), 100 ,((0.7*bgmedium.width))+200, bmpbs.height+100)
   sparkleRectOffset_medium6.Initialize((0.7*bgmedium.width), 600 ,((0.7*bgmedium.width))+200, bmpbs.height+600)
   sparkleRectOffset_medium7.Initialize((0.1*bgmedium.width), 650 ,((0.1*bgmedium.width))+200, bmpbs.height+650)
   sparkleRectOffset_medium8.Initialize((0.7*bgmedium.width), 650 ,((0.7*bgmedium.width))+200, bmpbs.height+650)

   'set the sparkles big
   sparkleRectOffset_big1.Initialize((0.1*bgbig.width), 100 ,((0.1*bgbig.width))+200, bmpbs.height+100)
   sparkleRectOffset_big2.Initialize((0.3*bgbig.width), 500 ,((0.3*bgbig.width))+200, bmpbs.height+500)
   sparkleRectOffset_big3.Initialize((0.4*bgbig.width), 100 ,((0.4*bgbig.width))+200, bmpbs.height+100)
   sparkleRectOffset_big4.Initialize((0.5*bgbig.width), 400 ,((0.5*bgbig.width))+200, bmpbs.height+400)
   sparkleRectOffset_big5.Initialize((0.7*bgbig.width), 100 ,((0.7*bgbig.width))+200, bmpbs.height+100)
   sparkleRectOffset_big6.Initialize((0.7*bgbig.width), 600 ,((0.7*bgbig.width))+200, bmpbs.height+600)
   sparkleRectOffset_big7.Initialize((0.03*bgbig.width), 800 ,((0.03*bgbig.width))+200, bmpbs.height+800)
   sparkleRectOffset_big8.Initialize((0.8*bgbig.width), 800 ,((0.8*bgbig.width))+200, bmpbs.height+800)
   
   'DrawBackground (Engine)
   sparkleRect.Initialize(0,0,200,200)
   starsmallrect.Initialize(0,0,250,250)
   starmediumrect.Initialize(0,0,500,500)
   starbigrect.Initialize(0,0,800,800)
   aRect.Initialize(0,0,Engine.ScreenWidth,Engine.ScreenHeight)

'   Log("arecoffset_small : " &aRectOffSet_small)
'   Log("arecoffset_medium : " &aRectOffSet_medium)
'   Log("arecoffset_big : " &aRectOffSet_big)
'   Log("arect : " &aRect)   
'   
   'Portrait
   If Engine.ScreenWidth <= 480 Then
      Engine.Canvas.DrawBitmap(bgsmall,aRectOffSet_small,aRect)
      getpattern
      If getpat="0" Then Engine.Canvas.DrawBitmapRotated(starbig,Null,starsmallrect_offset,Angle)
      If getpat="1" Then Engine.Canvas.DrawBitmapRotated(starbig2,Null,starsmallrect_offset,Angle)
      If getpat="2" Then Engine.Canvas.DrawBitmapRotated(starbig3,Null,starsmallrect_offset,Angle)
      If getpat="3" Then Engine.Canvas.DrawBitmapRotated(starbig4,Null,starsmallrect_offset,Angle)
      If getpat="4" Then Engine.Canvas.DrawBitmapRotated(starbig5,Null,starsmallrect_offset,Angle)
      If getpat="5" Then Engine.Canvas.DrawBitmapRotated(starbig6,Null,starsmallrect_offset,Angle)
      If getpat="6" Then Engine.Canvas.DrawBitmapRotated(starbig7,Null,starsmallrect_offset,Angle)
      If getpat="7" Then Engine.Canvas.DrawBitmapRotated(starbig8,Null,starsmallrect_offset,Angle)
      If getpat="8" Then Engine.Canvas.DrawBitmapRotated(starbig9,Null,starsmallrect_offset,Angle)
      If getpat="9" Then Engine.Canvas.DrawBitmapRotated(starbig10,Null,starsmallrect_offset,Angle)
      bmpbs.Initialize(File.DirAssets,anim.get(animindex))
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small1) ' ground...
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small2)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small3)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small4)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small5)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small6)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small7)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_small8)
      
   Else If Engine.ScreenWidth <= 960 Then
      Engine.Canvas.DrawBitmap(bgmedium,aRectOffSet_medium,aRect)
      getpattern
      If getpat="0" Then Engine.Canvas.DrawBitmapRotated(starbig,Null,starmediumrect_offset,Angle)
      If getpat="1" Then Engine.Canvas.DrawBitmapRotated(starbig2,Null,starmediumrect_offset,Angle)
      If getpat="2" Then Engine.Canvas.DrawBitmapRotated(starbig3,Null,starmediumrect_offset,Angle)
      If getpat="3" Then Engine.Canvas.DrawBitmapRotated(starbig4,Null,starmediumrect_offset,Angle)
      If getpat="4" Then Engine.Canvas.DrawBitmapRotated(starbig5,Null,starmediumrect_offset,Angle)
      If getpat="5" Then Engine.Canvas.DrawBitmapRotated(starbig6,Null,starmediumrect_offset,Angle)
      If getpat="6" Then Engine.Canvas.DrawBitmapRotated(starbig7,Null,starmediumrect_offset,Angle)
      If getpat="7" Then Engine.Canvas.DrawBitmapRotated(starbig8,Null,starmediumrect_offset,Angle)
      If getpat="8" Then Engine.Canvas.DrawBitmapRotated(starbig9,Null,starmediumrect_offset,Angle)
      If getpat="9" Then Engine.Canvas.DrawBitmapRotated(starbig10,Null,starmediumrect_offset,Angle)
      bmpbs.Initialize(File.DirAssets,anim.get(animindex))
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium1) ' ground...
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium2)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium3)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium4)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium5)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium6)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium7)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_medium8)
      
   Else If Engine.ScreenWidth <= 1280 Then
      Engine.Canvas.DrawBitmap(bgbig,aRectOffSet_big,aRect)
      getpattern
      If getpat="0" Then Engine.Canvas.DrawBitmapRotated(starbig,Null,starbigrect_offset,Angle)
      If getpat="1" Then Engine.Canvas.DrawBitmapRotated(starbig2,Null,starbigrect_offset,Angle)
      If getpat="2" Then Engine.Canvas.DrawBitmapRotated(starbig3,Null,starbigrect_offset,Angle)
      If getpat="3" Then Engine.Canvas.DrawBitmapRotated(starbig4,Null,starbigrect_offset,Angle)
      If getpat="4" Then Engine.Canvas.DrawBitmapRotated(starbig5,Null,starbigrect_offset,Angle)
      If getpat="5" Then Engine.Canvas.DrawBitmapRotated(starbig6,Null,starbigrect_offset,Angle)
      If getpat="6" Then Engine.Canvas.DrawBitmapRotated(starbig7,Null,starbigrect_offset,Angle)
      If getpat="7" Then Engine.Canvas.DrawBitmapRotated(starbig8,Null,starbigrect_offset,Angle)
      If getpat="8" Then Engine.Canvas.DrawBitmapRotated(starbig9,Null,starbigrect_offset,Angle)
      If getpat="9" Then Engine.Canvas.DrawBitmapRotated(starbig10,Null,starbigrect_offset,Angle)
      bmpbs.Initialize(File.DirAssets,anim.get(animindex))
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big1) ' ground...
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big2)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big3)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big4)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big5)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big6)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big7)
      Engine.Canvas.DrawBitmap(bmpbs,sparkleRect,sparkleRectOffset_big8)
      
   End If
   animindex=animindex+1      ' increase anim index to show picname+1 
   If animindex>29 Then animindex=0 ' block animindex at 51 coze we have 0+51=52 pics 
End Sub

'Fungsi untuk menganimasikan item ke atas
Sub MoveUp(Engine As LWEngine)
getnumber
   If xyinit = False Then 
      For i=0 To getnum-1
         bubblexrnd(i)=Rnd(5,Engine.ScreenWidth)
      Next
      For i=0 To getnum-1
         bubbleyrnd(i)=Engine.ScreenHeight+Rnd(1,Engine.ScreenHeight)
      Next
      For i=0 To bubbledynamicx.Length-1
         bubbledynamicx(i)=Rnd(5,Engine.ScreenWidth)
      Next
      For i=0 To bubbledynamicy.Length-1
         bubbledynamicy(i)=Engine.ScreenHeight+Rnd(1,Engine.ScreenHeight)
      Next      
      xyinit = True
   End If
   For i=0 To getnum-1
      Engine.Canvas.DrawBitmap(bubblesrndshow(i),Null,rectbubblerndshow(i))
      If bubblesrndshow(i) = bubblesrnd(0) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+10, bubbleyrnd(i)+10)
      Else If bubblesrndshow(i) = bubblesrnd(1) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+20, bubbleyrnd(i)+20)
      Else If bubblesrndshow(i) = bubblesrnd(2) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+30, bubbleyrnd(i)+30)
      Else If bubblesrndshow(i) = bubblesrnd(3) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+40, bubbleyrnd(i)+40)
      Else If bubblesrndshow(i) = bubblesrnd(4) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+40, bubbleyrnd(i)+40)
      Else If bubblesrndshow(i) = bubblesrnd(5) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+50, bubbleyrnd(i)+50)
      Else If bubblesrndshow(i) = bubblesrnd(6) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+100, bubbleyrnd(i)+100)
      End If
      
      If getspd==0 Then
         bubbleyrnd(i)=bubbleyrnd(i)-Rnd(0,2)
      Else If getspd==1 Then
         bubbleyrnd(i)=bubbleyrnd(i)-Rnd(1,3)
      Else If getspd==2 Then
         bubbleyrnd(i)=bubbleyrnd(i)-Rnd(5,10)
      End If
         
      If bubbleyrnd(i)<0 Then 
         bubbleyrnd(i)=Engine.ScreenHeight+Rnd(1,Engine.ScreenHeight)
         bubblexrnd(i)=Rnd(5,Engine.ScreenWidth)
      End If
   Next
   MoveUpDynamic(Engine)
End Sub
Sub MoveUpDynamic(Engine As LWEngine)
   Engine.Canvas.DrawBitmap(bubbledynamic(0),Null,bubbledynamicrect(0))
   Engine.Canvas.DrawBitmap(bubbledynamic(1),Null,bubbledynamicrect(1))
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(2),Null,bubbledynamicrect(2),Angle)
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(3),Null,bubbledynamicrect(3),Angle)
   Engine.Canvas.DrawBitmap(bubbledynamic(4),Null,bubbledynamicrect(4))
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(5),Null,bubbledynamicrect(5),Angle)
   Engine.Canvas.DrawBitmap(bubbledynamic(6),Null,bubbledynamicrect(6))
   bubbledynamicrect(0).Initialize(bubbledynamicx(0),bubbledynamicy(0),bubbledynamicx(0)+10,bubbledynamicy(0)+10)
   bubbledynamicrect(1).Initialize(bubbledynamicx(1),bubbledynamicy(1),bubbledynamicx(1)+20,bubbledynamicy(1)+20)
   bubbledynamicrect(2).Initialize(bubbledynamicx(2),bubbledynamicy(2),bubbledynamicx(2)+30,bubbledynamicy(2)+30)
   bubbledynamicrect(3).Initialize(bubbledynamicx(3),bubbledynamicy(3),bubbledynamicx(3)+40,bubbledynamicy(3)+40)
   bubbledynamicrect(4).Initialize(bubbledynamicx(4),bubbledynamicy(4),bubbledynamicx(4)+40,bubbledynamicy(4)+40)
   bubbledynamicrect(5).Initialize(bubbledynamicx(5),bubbledynamicy(5),bubbledynamicx(5)+50,bubbledynamicy(5)+50)
   bubbledynamicrect(6).Initialize(bubbledynamicx(6),bubbledynamicy(6),bubbledynamicx(6)+100,bubbledynamicy(6)+100)
   bubbledynamicy(0)=bubbledynamicy(0)-Rnd(6,7)
   bubbledynamicy(1)=bubbledynamicy(1)-Rnd(1,2)
   bubbledynamicy(2)=bubbledynamicy(2)-Rnd(2,3)
   bubbledynamicy(3)=bubbledynamicy(3)-Rnd(3,4)
   bubbledynamicy(4)=bubbledynamicy(4)-Rnd(6,7)
   bubbledynamicy(5)=bubbledynamicy(5)-Rnd(4,5)
   bubbledynamicy(6)=bubbledynamicy(6)-Rnd(2,3)
   For i=0 To bubbledynamic.Length-1
'   Angle = (Angle+AngleStep) Mod 360
   If bubbledynamicy(i)<0 Then 
         bubbledynamicy(i)=Engine.ScreenHeight+Rnd(1,Engine.ScreenHeight)
         bubbledynamicx(i)=Rnd(5,Engine.ScreenWidth)
   End If
   Next
End Sub

'Fungsi untuk menganimasikan item ke bawah
Sub MoveDown(Engine As LWEngine)
getnumber
   If xyinit = False Then 
      For i=0 To getnum-1
         bubblexrnd(i)=Rnd(5,Engine.ScreenWidth)
      Next
      For i=0 To getnum-1
         bubbleyrnd(i)=Rnd(-Engine.ScreenHeight,-5)
      Next
      For i=0 To bubbledynamicx.Length-1
         bubbledynamicx(i)=Rnd(5,Engine.ScreenWidth)
      Next
      For i=0 To bubbledynamicy.Length-1
         bubbledynamicy(i)=Rnd(-Engine.ScreenHeight,-5)
      Next
      xyinit = True
   End If
   For i=0 To getnum-1
      Engine.Canvas.DrawBitmap(bubblesrndshow(i),Null,rectbubblerndshow(i))
      If bubblesrndshow(i) = bubblesrnd(0) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+10, bubbleyrnd(i)+10)
      Else If bubblesrndshow(i) = bubblesrnd(1) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+20, bubbleyrnd(i)+20)
      Else If bubblesrndshow(i) = bubblesrnd(2) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+30, bubbleyrnd(i)+30)
      Else If bubblesrndshow(i) = bubblesrnd(3) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+40, bubbleyrnd(i)+40)
      Else If bubblesrndshow(i) = bubblesrnd(4) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+40, bubbleyrnd(i)+40)
      Else If bubblesrndshow(i) = bubblesrnd(5) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+50, bubbleyrnd(i)+50)
      Else If bubblesrndshow(i) = bubblesrnd(6) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+100, bubbleyrnd(i)+100)
      End If
      
      If getspd==0 Then
         bubbleyrnd(i)=bubbleyrnd(i)+Rnd(0,2)
      Else If getspd==1 Then
         bubbleyrnd(i)=bubbleyrnd(i)+Rnd(1,3)
      Else If getspd==2 Then
         bubbleyrnd(i)=bubbleyrnd(i)+Rnd(5,10)

      End If
      
      'Log("move"&move)
      If bubbleyrnd(i)>Engine.ScreenHeight Then 
         bubbleyrnd(i)=Rnd(-800,-5)
         bubblexrnd(i)=Rnd(5,Engine.ScreenWidth)
      End If
   Next
   MoveDownDynamic(Engine)
End Sub
Sub MoveDownDynamic(Engine As LWEngine)
   Engine.Canvas.DrawBitmap(bubbledynamic(0),Null,bubbledynamicrect(0))
   Engine.Canvas.DrawBitmap(bubbledynamic(1),Null,bubbledynamicrect(1))
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(2),Null,bubbledynamicrect(2),Angle)
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(3),Null,bubbledynamicrect(3),Angle)
   Engine.Canvas.DrawBitmap(bubbledynamic(4),Null,bubbledynamicrect(4))
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(5),Null,bubbledynamicrect(5),Angle)
   Engine.Canvas.DrawBitmap(bubbledynamic(6),Null,bubbledynamicrect(6))
   bubbledynamicrect(0).Initialize(bubbledynamicx(0),bubbledynamicy(0),bubbledynamicx(0)+10,bubbledynamicy(0)+10)
   bubbledynamicrect(1).Initialize(bubbledynamicx(1),bubbledynamicy(1),bubbledynamicx(1)+20,bubbledynamicy(1)+20)
   bubbledynamicrect(2).Initialize(bubbledynamicx(2),bubbledynamicy(2),bubbledynamicx(2)+30,bubbledynamicy(2)+30)
   bubbledynamicrect(3).Initialize(bubbledynamicx(3),bubbledynamicy(3),bubbledynamicx(3)+40,bubbledynamicy(3)+40)
   bubbledynamicrect(4).Initialize(bubbledynamicx(4),bubbledynamicy(4),bubbledynamicx(4)+40,bubbledynamicy(4)+40)
   bubbledynamicrect(5).Initialize(bubbledynamicx(5),bubbledynamicy(5),bubbledynamicx(5)+50,bubbledynamicy(5)+50)
   bubbledynamicrect(6).Initialize(bubbledynamicx(6),bubbledynamicy(6),bubbledynamicx(6)+100,bubbledynamicy(6)+100)
   bubbledynamicy(0)=bubbledynamicy(0)+Rnd(4,5)
   bubbledynamicy(1)=bubbledynamicy(1)+Rnd(1,2)
   bubbledynamicy(2)=bubbledynamicy(2)+Rnd(5,6)
   bubbledynamicy(3)=bubbledynamicy(3)+Rnd(3,4)
   bubbledynamicy(4)=bubbledynamicy(4)+Rnd(4,5)
   bubbledynamicy(5)=bubbledynamicy(5)+Rnd(4,5)
   bubbledynamicy(6)=bubbledynamicy(6)+Rnd(2,3)
   For i=0 To bubbledynamic.Length-1
'   Angle = (Angle+AngleStep) Mod 360
   If bubbledynamicy(i)>Engine.ScreenHeight Then 
         bubbledynamicy(i)=Rnd(-800,-5)
         bubbledynamicx(i)=Rnd(5,Engine.ScreenWidth)
   End If
   Next
End Sub

'Fungsi untuk menganimasikan item ke kiri
Sub MoveLeft(Engine As LWEngine)
getnumber   
   If xyinit = False Then 
      For i=0 To getnum-1
         bubblexrnd(i)=Engine.ScreenWidth+Rnd(1,Engine.ScreenWidth*2)
      Next
      For i=0 To getnum-1
         bubbleyrnd(i)=Rnd(1,Engine.ScreenHeight)
      Next
      For i=0 To bubbledynamicx.Length-1
         bubbledynamicx(i)=Engine.ScreenWidth+Rnd(1,Engine.ScreenWidth*2)
      Next
      For i=0 To bubbledynamicy.Length-1
         bubbledynamicy(i)=Rnd(1,Engine.ScreenHeight)
      Next
      xyinit = True
   End If
   For i=0 To getnum-1
      Engine.Canvas.DrawBitmap(bubblesrndshow(i),Null,rectbubblerndshow(i))
      If bubblesrndshow(i) = bubblesrnd(0) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+10, bubbleyrnd(i)+10)
      Else If bubblesrndshow(i) = bubblesrnd(1) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+20, bubbleyrnd(i)+20)
      Else If bubblesrndshow(i) = bubblesrnd(2) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+30, bubbleyrnd(i)+30)
      Else If bubblesrndshow(i) = bubblesrnd(3) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+40, bubbleyrnd(i)+40)
      Else If bubblesrndshow(i) = bubblesrnd(4) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+40, bubbleyrnd(i)+40)
      Else If bubblesrndshow(i) = bubblesrnd(5) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+50, bubbleyrnd(i)+50)
      Else If bubblesrndshow(i) = bubblesrnd(6) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+100, bubbleyrnd(i)+100)
      End If
      
      If getspd==0 Then
         bubblexrnd(i)=bubblexrnd(i)-Rnd(0,2)
      Else If getspd==1 Then
         bubblexrnd(i)=bubblexrnd(i)-Rnd(1,3)
      Else If getspd==2 Then
         bubblexrnd(i)=bubblexrnd(i)-Rnd(5,10)
      End If
      
'      Log("i"&bubblesrndshow(i))
      If bubblexrnd(i)<-50 Then 
         bubbleyrnd(i)=Rnd(1,Engine.ScreenHeight)
         bubblexrnd(i)=Engine.ScreenWidth+Rnd(1,Engine.ScreenWidth*2)
      End If
   Next
   MoveLeftDynamic(Engine)
End Sub
Sub MoveLeftDynamic(Engine As LWEngine)
   Engine.Canvas.DrawBitmap(bubbledynamic(0),Null,bubbledynamicrect(0))
   Engine.Canvas.DrawBitmap(bubbledynamic(1),Null,bubbledynamicrect(1))
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(2),Null,bubbledynamicrect(2),Angle)
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(3),Null,bubbledynamicrect(3),Angle)
   Engine.Canvas.DrawBitmap(bubbledynamic(4),Null,bubbledynamicrect(4))
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(5),Null,bubbledynamicrect(5),Angle)
   Engine.Canvas.DrawBitmap(bubbledynamic(6),Null,bubbledynamicrect(6))
   bubbledynamicrect(0).Initialize(bubbledynamicx(0),bubbledynamicy(0),bubbledynamicx(0)+10,bubbledynamicy(0)+10)
   bubbledynamicrect(1).Initialize(bubbledynamicx(1),bubbledynamicy(1),bubbledynamicx(1)+20,bubbledynamicy(1)+20)
   bubbledynamicrect(2).Initialize(bubbledynamicx(2),bubbledynamicy(2),bubbledynamicx(2)+30,bubbledynamicy(2)+30)
   bubbledynamicrect(3).Initialize(bubbledynamicx(3),bubbledynamicy(3),bubbledynamicx(3)+40,bubbledynamicy(3)+40)
   bubbledynamicrect(4).Initialize(bubbledynamicx(4),bubbledynamicy(4),bubbledynamicx(4)+40,bubbledynamicy(4)+40)
   bubbledynamicrect(5).Initialize(bubbledynamicx(5),bubbledynamicy(5),bubbledynamicx(5)+50,bubbledynamicy(5)+50)
   bubbledynamicrect(6).Initialize(bubbledynamicx(6),bubbledynamicy(6),bubbledynamicx(6)+100,bubbledynamicy(6)+100)
   bubbledynamicx(0)=bubbledynamicx(0)-Rnd(6,7)
   bubbledynamicx(1)=bubbledynamicx(1)-Rnd(1,2)
   bubbledynamicx(2)=bubbledynamicx(2)-Rnd(3,4)
   bubbledynamicx(3)=bubbledynamicx(3)-Rnd(3,4)
   bubbledynamicx(4)=bubbledynamicx(4)-Rnd(4,5)
   bubbledynamicx(5)=bubbledynamicx(5)-Rnd(4,5)
   bubbledynamicx(6)=bubbledynamicx(6)-Rnd(2,3)
   For i=0 To bubbledynamic.Length-1
'   Angle = (Angle+AngleStep) Mod 360
   If bubbledynamicx(i)<-50 Then 
         bubbledynamicy(i)=Rnd(1,Engine.ScreenHeight)
         bubbledynamicx(i)=Engine.ScreenWidth+Rnd(1,Engine.ScreenWidth*2)
   End If
   Next
End Sub

'Fungsi untuk menganimasikan item ke kanan
Sub MoveRight(Engine As LWEngine)
getnumber
   If xyinit = False Then 
      For i=0 To getnum-1
         bubblexrnd(i)=Rnd(-Engine.ScreenWidth*2,-120)
      Next
      For i=0 To getnum-1
         bubbleyrnd(i)=Rnd(1,Engine.ScreenHeight)
      Next
      For i=0 To bubbledynamicx.Length-1
         bubbledynamicx(i)=Rnd(-Engine.ScreenWidth*2,-120)
      Next
      For i=0 To bubbledynamicy.Length-1
         bubbledynamicy(i)=Rnd(1,Engine.ScreenHeight)
      Next
      xyinit = True
   End If
   For i=0 To getnum-1
      Engine.Canvas.DrawBitmap(bubblesrndshow(i),Null,rectbubblerndshow(i))
      If bubblesrndshow(i) = bubblesrnd(0) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+10, bubbleyrnd(i)+10)
      Else If bubblesrndshow(i) = bubblesrnd(1) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+20, bubbleyrnd(i)+20)
      Else If bubblesrndshow(i) = bubblesrnd(2) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+30, bubbleyrnd(i)+30)
      Else If bubblesrndshow(i) = bubblesrnd(3) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+40, bubbleyrnd(i)+40)
      Else If bubblesrndshow(i) = bubblesrnd(4) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+40, bubbleyrnd(i)+40)
      Else If bubblesrndshow(i) = bubblesrnd(5) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+50, bubbleyrnd(i)+50)
      Else If bubblesrndshow(i) = bubblesrnd(6) Then
         rectbubblerndshow(i).Initialize(bubblexrnd(i),bubbleyrnd(i),bubblexrnd(i)+100, bubbleyrnd(i)+100)
      End If
      
      If getspd==0 Then
         bubblexrnd(i)=bubblexrnd(i)+Rnd(0,2)
      Else If getspd==1 Then
         bubblexrnd(i)=bubblexrnd(i)+Rnd(1,3)
      Else If getspd==2 Then
         bubblexrnd(i)=bubblexrnd(i)+Rnd(5,10)
      End If
      
'      Log("i"&bubblesrndshow(i))
      If bubblexrnd(i)>Engine.ScreenWidth+50 Then 
         bubbleyrnd(i)=Rnd(1,Engine.ScreenHeight)
         bubblexrnd(i)=Rnd(-Engine.ScreenWidth*2,-120)
      End If
   Next
   MoveRightDynamic(Engine)
End Sub
Sub MoveRightDynamic(Engine As LWEngine)
   Engine.Canvas.DrawBitmap(bubbledynamic(0),Null,bubbledynamicrect(0))
   Engine.Canvas.DrawBitmap(bubbledynamic(1),Null,bubbledynamicrect(1))
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(2),Null,bubbledynamicrect(2),Angle)
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(3),Null,bubbledynamicrect(3),Angle)
   Engine.Canvas.DrawBitmap(bubbledynamic(4),Null,bubbledynamicrect(4))
   Engine.Canvas.DrawBitmapRotated(bubbledynamic(5),Null,bubbledynamicrect(5),Angle)
   Engine.Canvas.DrawBitmap(bubbledynamic(6),Null,bubbledynamicrect(6))
   bubbledynamicrect(0).Initialize(bubbledynamicx(0),bubbledynamicy(0),bubbledynamicx(0)+10,bubbledynamicy(0)+10)
   bubbledynamicrect(1).Initialize(bubbledynamicx(1),bubbledynamicy(1),bubbledynamicx(1)+20,bubbledynamicy(1)+20)
   bubbledynamicrect(2).Initialize(bubbledynamicx(2),bubbledynamicy(2),bubbledynamicx(2)+30,bubbledynamicy(2)+30)
   bubbledynamicrect(3).Initialize(bubbledynamicx(3),bubbledynamicy(3),bubbledynamicx(3)+40,bubbledynamicy(3)+40)
   bubbledynamicrect(4).Initialize(bubbledynamicx(4),bubbledynamicy(4),bubbledynamicx(4)+40,bubbledynamicy(4)+40)
   bubbledynamicrect(5).Initialize(bubbledynamicx(5),bubbledynamicy(5),bubbledynamicx(5)+50,bubbledynamicy(5)+50)
   bubbledynamicrect(6).Initialize(bubbledynamicx(6),bubbledynamicy(6),bubbledynamicx(6)+100,bubbledynamicy(6)+100)
   bubbledynamicx(0)=bubbledynamicx(0)+Rnd(4,5)
   bubbledynamicx(1)=bubbledynamicx(1)+Rnd(1,2)
   bubbledynamicx(2)=bubbledynamicx(2)+Rnd(5,6)
   bubbledynamicx(3)=bubbledynamicx(3)+Rnd(3,4)
   bubbledynamicx(4)=bubbledynamicx(4)+Rnd(4,5)
   bubbledynamicx(5)=bubbledynamicx(5)+Rnd(4,5)
   bubbledynamicx(6)=bubbledynamicx(6)+Rnd(2,3)
   For i=0 To bubbledynamic.Length-1
'   Angle = (Angle+AngleStep) Mod 360
   If bubbledynamicx(i)>Engine.ScreenWidth+50 Then 
         bubbledynamicy(i)=Rnd(1,Engine.ScreenHeight)
         bubbledynamicx(i)=Rnd(-Engine.ScreenWidth*2,-120)
   End If
   Next
End Sub

'Fungsi untuk mendapatkan arah pergerakan item dari setings
Sub getdirection
' Read file saved before to retriev Selected Spinner value.....
    If File.Exists(File.DirInternal,"heartdirection.txt") Then   
       getdir=File.ReadString(File.DirInternal,"heartdirection.txt")
    Else
       getdir="3"   ' 
    End If
   'Log("Direction :" &getdir)
End Sub

'Fungsi untuk mendapatkan speed item dari setings
Sub getspeed
' Read file saved before to retriev Selected Spinner value.....
    If File.Exists(File.DirInternal,"heartmovingspeed.txt") Then   
       getspd=File.ReadString(File.DirInternal,"heartmovingspeed.txt")
    Else
       getspd="1"   ' 
    End If
   'Log("Direction :" &getdir)
End Sub

Sub getpattern
' Read file saved before to retriev Selected Spinner value.....
    If File.Exists(File.DirInternal,"starpattern.txt") Then   
       getpat=File.ReadString(File.DirInternal,"starpattern.txt")
    Else
       getpat="1"   ' 
    End If
   'Log("Direction :" &getdir)
End Sub

'Fungsi untuk mendapatkan jumlah item di layar dari setings
Sub getnumber
' Read file saved before to retriev Selected Spinner value.....
    If File.Exists(File.DirInternal,"heartnumber.txt") Then
      If File.ReadString(File.DirInternal,"heartnumber.txt")=="" Then
         getnum="100"
      Else
          getnum=File.ReadString(File.DirInternal,"heartnumber.txt")
      End If
    Else
       getnum="100"   '  .....
    End If
   'Log("Direction :" &getnum)
End Sub

'Fungsi untuk mendapatkan status interaksi dari setings
Sub getdisableinteraction
' Read file saved before to retriev Selected Spinner value.....
    If File.Exists(File.DirInternal,"heartinteraction.txt") Then   
       getitrc=File.ReadString(File.DirInternal,"heartinteraction.txt")
    Else
       getitrc="False"   ' 
    End If
End Sub

Sub getheartvisible
' Read file saved before to retriev Selected Spinner value.....
    If File.Exists(File.DirInternal,"heartvisible.txt") Then   
       getvisible=File.ReadString(File.DirInternal,"heartvisible.txt")
    Else
       getvisible="False"   ' .
    End If
End Sub

Sub getrotatespeed
' Read file saved before to retriev Selected Spinner value.....
    If File.Exists(File.DirInternal,"starrotatespeed.txt") Then   
       getrotspd=File.ReadString(File.DirInternal,"starrotatespeed.txt")
    Else
       getrotspd="2"   ' default bubble speed is 25 ms .....
    End If
   'Log("Direction :" &getdir)
End Sub

Basically, I created 3 separate BG for each device type, so that when I detect small device, I will use small bg, if I detect medium device, I will use medium bg and when big HD device such as S3, I will use big bg.

And to change livewallpaper setting, I didn't use preference manager, but I manually save each configuration in a files.

The crash happened really often (sometime 100%) on S3 when you do this step.
1. install the LWP
2. previews the LWP once
3. Set as wallpaper
4. Go to preview again.
5. Then the livewallpaper crash with out of memory occur on the crash log.

I still unable to figure out how to fix this.

I know it is a long code, but really appreciated if anyone can give an advice on how to efficiently load bitmap from my code above.

I also add in the attachment, the crash log from samsung certification team, they reject my app submission due to this crash while under test review.

Thanks. waiting for your input guys. :sign0104::sign0188:
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
You need to consider the following for OOM errors:
How many bitmaps do you have loaded in memory at one time and what are their dimensions?
The size of your canvas object will be equal to your device resolutions.

As you said for the S3 you use big big images, so that probably tips you over the limit. I'm not sure how much process memory is availabe to the S3, the min is 16MB, but new devices have more.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Your code crashes on my device because some files are missing so I cannot help a lot.
I can just give the usual advices:
- try to reduce the colors from ARGB888 to RGB565
- try to use image files adapted to the screen size, instead of loading a very big one and rescaling it
 
Upvote 0

uswin4224

Member
Licensed User
Longtime User
Your code crashes on my device because some files are missing so I cannot help a lot.
I can just give the usual advices:
- try to reduce the colors from ARGB888 to RGB565
- try to use image files adapted to the screen size, instead of loading a very big one and rescaling it

Hi Informatix, thanks a lot for your respond, I already edit my first post, this is the complete project zip, it contain all of my image. Really appreciated it guys if you willing to have a try.

try the VBBitmap Library to load the images

http://www.b4x.com/forum/additional...tended-safer-loadbitmapsample.html#post109992

download the libraries, and I edited your project
please test, I am curious

8)

VB1992, thanks for your library, let me try this and see the result asap. will get back to you. :sign0188:
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Hi Informatix, thanks a lot for your respond, I already edit my first post, this is the complete project zip, it contain all of my image. Really appreciated it guys if you willing to have a try.

With the new files you provided, I understood the reason of your OOM. The big.jpg file is too big. It is supposed to be displayed on screens with a resolution between 960 and 1280 pixels. So why is its native size 1605x1420 ? That eats 9Mb of memory just to load it. Resize it to something like 1280x1132 (or 1024x906, because you can't see every pixel on a 1280x720 device with a very high density, so displaying them is a waste of memory) and that should be ok.
 
Upvote 0
Top