ilan Expert Licensed User Longtime User Jul 20, 2016 #1 let say you have an imageview and you would like to show an animation in it. so let say your animation has 5 images. you could do something like this create an array of all bitmaps Code: Sub Process_Globals '... Dim img As ImageView Dim bmp(5) As Image End Sub then intialize the bitmaps (note that we name the images like this: pic0.png, pic1.png, pic2.png,...) Code: '... For i = 0 To bmp.Length-1 bmp(i).Initialize(File.DirApp,"pic" & i & ".png") Next '... now come the tricky part because we would like to show an animation that always continue we can say something like this: Code: Sub timer_tick index = index + 1 If index > bmp.Length-1 Then index = 0 End If img.SetImage(bmp(index)) End Sub it will work but we could make our code shorter if we use MODULUS Code: Sub timer_tick index = (index + 1) Mod 5 img.SetImage(bmp(index)) End Sub
let say you have an imageview and you would like to show an animation in it. so let say your animation has 5 images. you could do something like this create an array of all bitmaps Code: Sub Process_Globals '... Dim img As ImageView Dim bmp(5) As Image End Sub then intialize the bitmaps (note that we name the images like this: pic0.png, pic1.png, pic2.png,...) Code: '... For i = 0 To bmp.Length-1 bmp(i).Initialize(File.DirApp,"pic" & i & ".png") Next '... now come the tricky part because we would like to show an animation that always continue we can say something like this: Code: Sub timer_tick index = index + 1 If index > bmp.Length-1 Then index = 0 End If img.SetImage(bmp(index)) End Sub it will work but we could make our code shorter if we use MODULUS Code: Sub timer_tick index = (index + 1) Mod 5 img.SetImage(bmp(index)) End Sub
ilan Expert Licensed User Longtime User Jul 20, 2016 #2 another example, we would like the animation to stop when it reaches the last index of the bmp array (like a 1 time animation of a sprite). so we could say something like this: Code: Sub timer_tick index = index + 1 If index > bmp.Length-1 Then index = bmp.Length-1 End If img.SetImage(bmp(index)) End Sub but using the MIN option will make our code shorter Code: Sub timer_tick index = Min(index + 1, bmp.Length-1) img.SetImage(bmp(index)) End Sub
another example, we would like the animation to stop when it reaches the last index of the bmp array (like a 1 time animation of a sprite). so we could say something like this: Code: Sub timer_tick index = index + 1 If index > bmp.Length-1 Then index = bmp.Length-1 End If img.SetImage(bmp(index)) End Sub but using the MIN option will make our code shorter Code: Sub timer_tick index = Min(index + 1, bmp.Length-1) img.SetImage(bmp(index)) End Sub
S sorex Expert Licensed User Longtime User Jul 21, 2016 #3 ilan said: Code: index = (index + 1) Mod 5 Click to expand... you could use Code: index = (index + 1) Mod bmp.lenght if the amount of frames changes you don't need to touch the code.
ilan said: Code: index = (index + 1) Mod 5 Click to expand... you could use Code: index = (index + 1) Mod bmp.lenght if the amount of frames changes you don't need to touch the code.