In this place...you can see pics for tattoo, ciber art, xp themes and more
Help in DX scripting
Published on August 31, 2008 By DaRkFuSsIoOn In WinCustomize Talk
hi guys, need some help in DX...I'm doing a widget for my daugther, Is only one animation, but i have a problem, the animation has 145 frames, what i want is a sound in the frame 56....any idea  =S
Comments
on Aug 31, 2008
The only way I can think of is probably a lot of work but...

Create an object with 145 states. Assign the correct image to each state. Assign your sound for state number 56. Then a short script like:

On command_executed
For i = 1 to 145
MyObject.State = i
next.

Since you already have your animation strip made there's probably a quicker way to wrtie the animation script and trap the 56 frame but, I don't know what it is.
on Aug 31, 2008
If you check the "Scripted" option in the animation panel, you get access to the property Object.CurrentFrame.

You can then create a loop in your script and check for frame number 56


For i = 0 To 145
Object.CurrentFrame = i

If i = 56 Then
'play your sound here
End If
Next
on Aug 31, 2008
Edit: Ignore below as Littleboy's way is smoother but, I'm leaving this for other potential ideas.

The easiest way I can think of is to break it into two animations.

Animation1 being frames 0 to 55
Animation2 being frames 56 to 145

Depending on your animation settings then you'd do something like this:
* Note I haven't tested this
Code: vbscript
  1. ' Animation Image, Frames, Speed, Command
  2. Object.SetPicture "Animation1.png",56,100,&H00000001
  3. Object.SetTimer 1, 5600 ' Speed needs to equal length of first animation
  4. Sub Object_OnTimer1
  5. Object.Sound= "mysound.wav"
  6. Object.SetPicture "Animation2.png",89,100,&H00000001
  7. Object.KillTimer 1
  8. End Sub


If you're doing a continual loop animation then set up a second timer and call it from within timer 1, then call timer1 from inside timer 2.
Make sure to kill both timer's on exit
on Sep 01, 2008
and how can I call States ?? example...
State1 = animation 0-55
State2 = animation 56-70 ----> this is the animation with the sound
State3 = animation 70-145
And then "Mouse up" = a little loop animation of 17 frames

Is this posible ??

thankx for your help guys, but it does not works =S I'm new on this kind of code
on Sep 02, 2008
What triggers the animation? Why the 3 states explain more.
on Sep 02, 2008
Hi BigDogBigFeet...I dont know how make it in only one animation, is because I'm trying to make 3 states for it, the animation is a little mouse who suposes is walking ---> State1, and then he stops and says Hi moving his hand --->State2 on the state3 only moves his head at the left and do nothing,
It suposes to show and hide a little window with some link buttons, they will open some flash games as a targets, they are located in a folder, they already done.....and the State "4" is a "mouse up" state is a loop animation whit 17 frames, and this is the last animation for the mouse is only moving his legs and head.

I was thinking in make the animations as calling states at the end of the animations, but I dont know how, I was thinking in the events CuerrentFrame, something like this :

"for the animation1":

If object.CurrentFrame = 55 Then
desktopx.object("mouse").State = "Estado1"
function OnState1()
End If

"for the animation2":

Function OnState1
If object.CurrentFrame = 70 Then
desktopx.object("mouse").State = "Estado2"
function OnState2()
End If
End Function

"and this for animation3":

Function OnState2
desktopx.object("mouse").State = "Estado3"
End Function

I dont know how can I make the codes in DesktopX =S hope you can give me a hand
on Sep 02, 2008
Do you have a button that launches the mouse? If so put the code to control the mouse in the button. You will have to use for loops to control the appearance of walking and for timing each sequence. You won't need these functions above. Instead put this in the button that launches the mouse.

Sub Object_OnLButtonUp(x,y,dragged)
If Not dragged Then
desktopx.object("mouse").State = "Estado1"
For i = 1 to 55
desktopx.object("mouse").Left = desktopx.object("mouse").Left + 1 '< for movement
Object.CurrentFrame = i
Next
desktopx.object("mouse").State = "Estado2" ' < assign the sound here in properties
For i = 1 to 15 ' < 56 to 70 = 15 frames
Object.CurrentFrame = i
Next
desktopx.object("mouse").State = "Estado3"
For i = 1 to 75 ' < 71 to 145 = 75 frames
Object.CurrentFrame = i
Next
desktopx.object("mouse").State = "Estado4"
Enf If
End Sub

This is the basic idea. It will also need logic to test if the mouse is visible or not so you can reset the position of the mouse back to the starting point. If the mouse is going to be the button then just put this script in the mouse.
on Sep 02, 2008
I'd agree with Littleboy, use scripted animation, with all the frames in one state - this will result in a smoother animation than if the frames are split between multiple states (desktopx clears unused images from memory, including images in object states that haven't been used for a while).

Instead of a For...Next loop, you should use a timer to control the animation, so you can define the time between frames and allow the object to remain responsive whilst animating.

To play a sound at frame 56, you can have a second (hidden) object which contains your sound. Give this object 2 states - the first state contains no sound (otherwise it will play the sound when dx loads), the 2nd state contains your sound effect. When your animation hits frame 56 then call

desktopx.object("soundeffects").State = "playsound"

For details of timers, scripted animation and other desktopx scripting information check out the desktopX scripting reference: https://www.stardock.com/products/desktopx/help/dev_guide_3b_script_reference.htm
on Sep 13, 2008

I've make it !!!  thank you very much guys