simple test to see if I could read a single sprite sheet and walk thru it. This uses an image of a deck of cards. The key is to declare an array of source rectangle, intialize them from the source rectangle, then display them. Works well for me.
here is the code:
here is the code:
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim can1 As Canvas
Dim b1 As Bitmap
Dim r As Rect
Dim s(55) As Rect
Dim lv As LayoutValues
Dim inc As Int
Dim pos As Int
Dim Speed As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
speed = 500
Activity.LoadLayout("main")
timer1.Initialize("timer1",speed)
timer1.Enabled = True
can1.Initialize(activity)
b1.Initialize(File.DirAssets, "cards.png")
x = 10
y = 10
lv = GetDeviceLayoutValues
r.Initialize(10,10,lv.Width - 10 ,lv.Height - 10 )
For i = 0 To 4
For ii = 0 To 10
s(pos).Initialize(68 * ii, 96 * i,68 * (ii + 1),96 * (i + 1))
'the sprite sheet is 11 cols x 5 rows. The image is 748x480, so, the dest rect needs to read in 68x96 (748 / 11 = 68, 480 / 5 = 96)
pos = pos + 1
Next
Next
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub timer1_tick()
can1.DrawBitmap(b1,s(inc),r)
activity.Invalidate2(r)
inc = inc + 1
If inc > 54 Then
inc = 0
End If
End Sub