I have an object that consists of a sequence of sprites. When I initiate the object and use Animator.SetFrames, everything works fine.
Later, I want to have the object load up a different set of frames, but when I do it, it just shows the first frame and the animator doesn't cycle through the new set of sprites.
Here is the initial setup:
Here is the change code in a different class:
Don't get confused by the "i+1" when loading up the Arrays. The sprite sheet has more than 5 cells in it. I just want a specific range.
Thoughts?
-Sterling
Later, I want to have the object load up a different set of frames, but when I do it, it just shows the first frame and the animator doesn't cycle through the new set of sprites.
Here is the initial setup:
B4X:
Public Sub AddLeroy (x As Int, y As Int, size As Int)
Dim animator As SpriteAnimator
Dim rects(5) As Rect
Dim bitmaps(5) As Bitmap
Dim row As Int
row = 0
'The Leroy sprite sheet includes 1 row of sprites.
For i = 0 To 4
rects(i) = leroyBitmaps(i+1, row).SrcRect
bitmaps(i) = leroyBitmaps(i+1, row).Bitmap
Next
animator.Initialize
Dim bd As BitmapData
animator.SetFrames(bd, rects, bitmaps) 'sets the frames that will be animated
animator.AnimationInterval = 10
MyLeroy.Initialize(bd, animator, Me, x, y, size)
gv.BitmapsData.Add(bd) 'add Leroy to the GameView (so it will be redrawn every time).
End Sub
Here is the change code in a different class:
B4X:
If game.pad.moving <> 0 Then
Dim Rects(5) As Rect
Dim bitmaps(5) As Bitmap
For i = 0 To 4
Rects(i) = game.leroyBitmaps(i+1, 0).SrcRect
bitmaps(i) = game.leroyBitmaps(i+1, 0).Bitmap
Next
animator.SetFrames(leroyBd, Rects, bitmaps) 'sets the frames that will be animated
animator.AnimationInterval = 10
prevSpriteSeq = 1 'set to walking
Else
Don't get confused by the "i+1" when loading up the Arrays. The sprite sheet has more than 5 cells in it. I just want a specific range.
Thoughts?
-Sterling