Learning DX Step-By-Step - #11

Animation Station

Wednesday, June 06, 2007 by RomanDA | Discussion: DesktopX Tutorials

Step-by-Step Tutorials

#11 - Animation

A series by RomanDA

Listing of other DX Tutorials: Click here
Today's Lesson: "Animation"

Ok, So.. I lied.  Well I didn't Lie, I really was done, but this one was really simple and I saw some people asking about this, and I had just finished making just this thing.  I figured why not.
So call it a bonus for me becoming a Master.. or call it, I was bored.

We will be Using the SCRIPTED Animation check you have seen in the Object "Animation" tab.

For this and all the Step-By-Step DX Tutorials you will need to purchase DesktopX for $14.95 from Stardock.

Lets get started.

STEP 1 - Create the objects


We are going to make a single object here, but its more complicated then normal.

First thing you have to do is make a PNG that has multiple images inside it.  There are a LOT of ways to make this kind of PNG.

I have used FLASH to export a series of images, then they all need to be complied into one image.
Like this:

The trick with the frames (objects) in this kind of image is that the need to be EXACTLY The same size, and they have to be spaced EXACTLY the same as well.
In this case the image has 4 frames, I numbered them for you so you will be able to see the animation in action.

Create a NEW object, call it "TEST" or whatever. 
You can (save-as) the above image, and use it for testing.  The Catch here is make sure you change the ANIMATION TAB in the STATES tab of the properties to show:

(4) Frames, and SCRIPTED is checked.

STEP 2 - Moving Ahead - Add a Script


Create a SCRIPT on the object we just created.

ANIMATION Code
  Function Object_OnLButtonUp(x, y, Dragged)
  If Dragged = False Then
    CurFrame = object.CurrentFrame + 1
    If CurFrame < 4 Then
      object.CurrentFrame = CurFrame
    Else
      object.CurrentFrame = 0
    End If
  End If
End Function

Lets look at the above script.
First we use the same function we use all the time to handle click:

ANIMATION Code
  Function Object_OnLButtonUp(x, y, Dragged)
  If Dragged = False Then

Here is the main part of the script.  The script looks at the object to see what its Current Frame is.
CurFrame = object.CurrentFrame + 1
This is based on 0-3 not 1-4, even though there are 4 frames in the animation.  We START at 0 not 1!!!!

Then we check to see if CurFrame its less than < the max number of frames (4 frames of animation).
If so, then we make the current frame the new CurFrame.

Or else the object's CurrentFrame is set to 0 (the first frame of the animation).

ANIMATION Code
      CurFrame = object.CurrentFrame + 1
    If CurFrame < 4 Then
      object.CurrentFrame = CurFrame
    Else
      object.CurrentFrame = 0
    End If

CONCLUSION


So, that's about it.  you click on the object, and it changes the current frame up 1 each time till it gets to the last frame, then it goes back to 0.
I used this in something I'm working on right now.

I hope you took the time to enter the code (not just copy/pasted the entire thing) so you could work thru the tutorial step-by-step and see how things work. 

This one was very simple, but I know I didn't know how to use this till I had to, so I hope it helps everyone out.

This REALLY will be my last tutorial for a while.  I hope you have enjoyed this step into DX.

Enjoy,
RomanDA
AKA: David A. Roman
http://romanda.wincustomize.com
elvee
Reply #1 Wednesday, June 06, 2007 9:46 PM

I hope you took the time to enter the code (not just copy/pasted the entire thing) so you could work thru the tutorial step-by-step and see how things work.

For me, that is really the best way to do it. For some strange reason, copying and pasting script for DX, gave me scripting errors...don't know why.

Anyway, Thanks for the bonus Dave. Great and informative as always  

ZubaZ
Reply #2 Wednesday, June 06, 2007 11:36 PM
Nice job knocking this out Master RomanDA!
Quentin94
Reply #3 Thursday, June 07, 2007 3:21 AM
MASTER DX again Thanks for the time you take to show us this
RomanDA
Reply #4 Thursday, June 07, 2007 4:58 PM
For some strange reason, copying and pasting script for DX, gave me scripting errors.


its possible the [ code ] block in there could mess things up.
jpkylegirl
Reply #5 Tuesday, July 10, 2007 4:44 PM
well, well, well... I think I finally caught up.  You can stop anytime ya know.

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!

Articles Filters

Category:
View:
Search:
Apply



walnut3