Image Animation Script help needed (Solved)

I need help in making a animation script, What I'm trying to do is make an infinitely repeating animated image from a sprite strip that I have all ready made (20 Frames) to run on the desktop. Normally I would just use the animation feature but I need to change the duration of most the the frames (see below) to maintain the proper movement of the animated image. Any help would be greatly appreciated.

Frame 1:        200ms
Frame 2-5:       10ms
Frame 6:        100ms
Frame 7-9:       10ms
Frame 10:        12ms
Frame 11:        15ms
Frame 12:        25ms
Frame 13-14:     8ms
Frame 15:          0ms
Frame 16:          6ms
Frame 17:          0ms
Frame 18-20:     5ms
Repeat:         Infinite
12,929 views 7 replies
Reply #1 Top
Did you see these two pages:
Reply #2 Top
There are a few ways to do what you want. I didn't test this code however I'm sure that it will work.

Dim num,td '<== frame number and time delay

Sub Object_OnLButtonUp(x,y,dragged)
If Not dragged Then
num = 1 : SetKey(1)
End If
End Sub

Sub SetKey(n)
Select Case n
Case 1 td = 200
Case 2,3,4,5 td = 10
Case 6 td = 100
Case 7,8,9 td = 10
Case 10 td = 12
Case 11 td = 15
Case 12 td = 25
Case 13,14 td = 8
Case 15,17 td = 0
Case 16 td = 6
Case 18,19,20 td = 5
End Select
If td > 0 Then Object.SetTimer 1,td Else Object_OnTimer1
End Sub

Sub Object_OnTimer1
Object.KillTimer 1
desktopx.object("frame").state = num '<== state names from 1 to 20
If num < 20 Then num = num + 1 Else num = 1
Call SetKey(num)
End Sub

As well as you may create the array with path to each of your images:

Dim frame(20),num,td

Sub Object_OnScriptEnter
For n = 1 To 20
frame(n) = "C:\My Pictures\image"&n
Next
End Sub

then use this code to change frames:

Sub Object_OnTimer1
Object.KillTimer 1
desktopx.object("frame").picture = frame(num)
If num < 20 Then num = num + 1 Else num = 1
Call SetKey(num)
End Sub

Best Regards.  ;) 
Reply #3 Top
Vad_M, Thanks for the time to help me. I tried the first part of your script as that is what I am aiming at but have yet to get it to work, I did change "frame" to the ObjectId that I set "Test1" but it didn't work. I did notice that the last two If statements did not have End If at the end but that did not fix it I also tried reformatting the last two If statements with End If but that didn't help either.

Here is a Simple Test Image and a dxpack of the Script using the Test Image


Test1.png


www.myminifile.com Test1.dxpack
Reply #4 Top
No any problems!

1. Set the object width/height to 100 (in the 'Summary' tab) - your frame size is 100 x 100.
2. Copy and paste this code into the object:

Dim num,td '<== frame number and time delay

Sub Object_OnScriptEnter
object.CurrentFrame = 0
End Sub

Sub Object_OnLButtonUp(x,y,dragged)
If Not dragged Then
num = 0 : SetKey(0)
End If
End Sub

Sub SetKey(n)
Select Case n
Case 0 td = 200
Case 1,2,3,4 td = 10
Case 5 td = 100
Case 6,7,8 td = 10
Case 9 td = 12
Case 10 td = 15
Case 11 td = 25
Case 12,13 td = 8
Case 14,16 td = 0
Case 15 td = 6
Case 17,18,19 td = 5
End Select
If td > 0 Then Object.SetTimer 1,td Else Object_OnTimer1
End Sub

Sub Object_OnTimer1
Object.KillTimer 1
object.CurrentFrame = num '<== state names from 0 to 19
If num < 19 Then num = num + 1 Else num = 0
Call SetKey(num)
End Sub

3. Enjoy.  ;) 
+1 Loading…
Reply #5 Top
It works! Thank you Vad_M. I did need need to change a few things like removing Object_OnLButtonUp and moving its contents to Object_OnScriptEnter to start animation on load instead of on left click nothing major. The other thing I changed was actually my fault to begin with, the delay time as it was running way to fast. I realized that the duration that wrote down was supposed to be 1/100 not 1/1000 of a second, adding a extra zero to my time fixed that. And the last thing I changed was the frame numbers in Sub SetKey(n) as for sum reason even though that DesktopX: Scripted Animations tells that frame numbers start with zero that my animation would delay one frame too early, changing it so that it starts with One instead of Zero fixed that problem. After that the script was fully working for me. :CONGRAT:


Code: vbscript
  1. Dim num,td '<== frame number and time delay
  2. Sub Object_OnScriptEnter
  3. object.CurrentFrame = 0
  4. num = 0 : SetKey(0)
  5. End Sub
  6. Sub SetKey(n)
  7. Select Case n
  8. Case 1 td = 2000
  9. Case 2,3,4,5 td = 100
  10. Case 6 td = 1000
  11. Case 7,8,9 td = 100
  12. Case 10 td = 120
  13. Case 11 td = 150
  14. Case 12 td = 250
  15. Case 13,14 td = 80
  16. Case 15,17 td = 0
  17. Case 16 td = 60
  18. Case 18,19,20 td = 50
  19. End Select
  20. If td > 0 Then Object.SetTimer 1,td Else Object_OnTimer1
  21. End Sub
  22. Sub Object_OnTimer1
  23. Object.KillTimer 1
  24. object.CurrentFrame = num '<== state names from 0 to 19
  25. If num < 19 Then num = num + 1 Else num = 0
  26. Call SetKey(num)
  27. End Sub
Reply #6 Top
Oops, In the last post the script didn't post correctly so here it is again.


Dim num,td '<== frame number and time delay

Sub Object_OnScriptEnter
object.CurrentFrame = 0
num = 0 : SetKey(0)
End Sub

Sub SetKey(n)
Select Case n
Case 1 td = 2000
Case 2,3,4,5 td = 100
Case 6 td = 1000
Case 7,8,9 td = 100
Case 10 td = 120
Case 11 td = 150
Case 12 td = 250
Case 13,14 td = 80
Case 15,17 td = 0
Case 16 td = 60
Case 18,19,20 td = 50
End Select
If td > 0 Then Object.SetTimer 1,td Else Object_OnTimer1
End Sub

Sub Object_OnTimer1
Object.KillTimer 1
object.CurrentFrame = num '<== state names from 0 to 19
If num < 19 Then num = num + 1 Else num = 0
Call SetKey(num)
End Sub
Reply #7 Top
I'm glad that all okay now.  :) 

Have a nice day with DesktopX!