Welcome Guest ( Log In | Register )

6 Pages V   1 2 3 > »   
Reply to this topicStart new topic
> Creating A Zipper In Swishmax, Intermediate - Advanced
Eddie_K
post May 6 2005, 05:05 AM
Post #1


Hush now, I'm thinking...
Group Icon
Group: *Premier*
Posts: 3,977
Joined: 25-May 04
From: Heaven
Member No.: 47





Creating a SwishMax Zipper - tutorial

Hi there Tip-Hat.gif . I'm going to explain how to build your own zipper with action in SwishMax. This will look like in the image below, a working version can be seen :: Here ::

Attached Image

You can download the source for the zipper here:
http://www.13dots.com/forum/index.php?auto...mp;showfile=207


First off we are going to create the zipper teeth. For this I have created a 12w /2.5h px rectangle, and copy pasted 32 times, like in the image below.

Attached Image

When I finished the teeth alignement, I started renaming them, l1-l16 (for the left teeth) and r1-r16 (for the right teeth). You will also need to check the Target checkbox for each tooth, because later on we need to animate these, as we drag the zipper downwards . For a zipper ending, I have added a larger rectangle at the bottom. When done, group all as a sprite and rename it teeth. Below is a rough sketch of the teeth...

Attached Image


Now, for the zipper puller, I have drawn in vector the image below:

Attached Image

I grouped all the shapes in a sprite and named it zipper. If you open up the zipper sprite you'll notice I have a slightly complicated arrangement.

Attached Image

This is because I wanted the light-grey part of the puller to balance when not pressed, and stop ballancing once it's pressed. So I have two states... One when this moves (balance2) and a state where it's stopped (balance).

Now... moving on to making this zipper interact with the user. I have added the following code for the zippa sprite. This contains all the elements of the zipper, and at his turn is contained in the sprite called zipper. You may wonder why all this grouping as sprite... Well, my code will not function correctly otherwise, as I'll actually add my code to the zippa sprite, making it dependant of the zipper sprite, BUT independent of the main scene's timeline. I'm a sprite kind of guy, don't like to work with scenes :whistle: . So... here is the code for zippa:

CODE
[color="blue"]on (press) {
_root.prs=1;
startDragUnlocked(145,145,250,400);
}
on (release) {
stopDrag();
_root.prs=0;
}[/color]



You may wonder what does this all mean... Well easy... We have two states for the sprite, once it's pressed and once it's released. As you remember from before, I have implemented a balancing option, to activate this, I have defined a variable called prs in the _root of my movie to control this action. It will all make sense, once we get to the main code of the movie, located in the _root of the movie. To give the user the possibility to drag the zipper, I have added the startDragUnlocked(145,145,250,400); code. This tells me that the user can drag the zipper on a constant _X of 145 and a variable _Y from 250 to 400.

Now, for the final touch of our movie, we'll add the code to the _root of our movie. For this click on Scene_1 and add the following code:

CODE
[color="blue"]onload () {
fact=0;
prs=0;
}
onEnterFrame() {
if (prs==0) {
zipper.zippa.zip.gotoAndStop(2);
} else {
zipper.zippa.zip.gotoAndStop(1);
}

dist=zipper._Y-250;
for (i=1; i<=16; i++) {
fact= math.exp(i/3*0.9+.5);
_root.teeth["l"+i]._X = -3-(dist/fact);
_root.teeth["r"+i]._X = 3+(dist/fact);
}
}
[/color]


What does all of this mean ? Well easy... First of all we define two variables called fact and prs. The prs is used for telling our movie if the zipper is pressed or not and fact is used in the code below.
What does onEnterFrame() mean? It means that this action will be performed continuously.



CODE
if (prs==0) {
zipper.zippa.zip.gotoAndStop(2);
} else {
zipper.zippa.zip.gotoAndStop(1);
}



With these lines I tell my zipper what action to do... balance or not. In case my zipper is pressed, stay static, else balance. Easy.

Probably the most confusing part of our zipper code and what makes actually the teeth move when dragging the zipper up or down is below


CODE
dist=zipper._Y-250;
for (i=1; i<=16; i++) {
fact= math.exp(i/3*0.9+.5);
_root.teeth["l"+i]._X = -3-(dist/fact);
_root.teeth["r"+i]._X = 3+(dist/fact);
}


Remember... all of this is executed "real-time" so my movie is refreshing itself every second. I have declared a variable dist to apreciate the distance where my zipper's _Y is. As we declared above on the dragging code, our zipper drags from _Y 250 to 400. dist is a variable that substracts from this interval 250, leaving me with an interval of 0-150. This way I can exactly tell my movie how far the teeth have to be from my zipper.

The following code is actually what makes the zipper teeth move from my zipper puller. To save a lot of my time, I have created a FOR function that will always loop through all my 16 teeth (on each side) of the zipper, so I can change their properties all at once.
I declared a variable called fact, that actually represents the factor of how the teeth will move on the _X axis. I'm not such a math wiz, but I used math.exp (exponential) for a curve that should have looked like

Attached Image

I did all my best smile.gif , my variable beeing the i value from the FOR function.


CODE
_root.teeth["l"+i]._X = -3-(dist/fact);
_root.teeth["r"+i]._X = 3+(dist/fact);


After declaring my "movement" function, I had to make the teeth follow the graphic of this funtion. So I have moved the left and right teeth using _root.teeth["side"+i]._X, and where our i takes values from 1-16 all the time, like a loop.
The -3-(dist/fact); code represents the movement on the _X axis. This is the distance of movement divided by the factor, so meaning 0-150/curve. So it will move my zipper teeth according to the position of my zipper puller.

This concludes this tutorial. If you want to play, just modify for the variable fact the function, and I'm sure you'll have lots of fun. I know I did, obtaining very weird movements.
Hope this tut was pretty clear :whistle: , and questions, feel free to ask.

Yours,
Eddie
 
+Quote Post  Go to the top of the page
*D*
post May 6 2005, 08:15 AM
Post #2


Merry KissMoose
Group Icon
Group: Main Team
Posts: 15,990
Joined: 18-May 04
From: North Pole
Member No.: 2





Very nicely explained and easy to follow Eddie

Thankyou flowers.gif
 
+Quote Post  Go to the top of the page
Eddie_K
post May 6 2005, 12:37 PM
Post #3


Hush now, I'm thinking...
Group Icon
Group: *Premier*
Posts: 3,977
Joined: 25-May 04
From: Heaven
Member No.: 47





Thanks smile.gif It's pretty long, but hopefully people can understand my mumblings Doh.gif

Eddie
 
+Quote Post  Go to the top of the page
StarSkreem
post May 6 2005, 07:47 PM
Post #4


Far Beyond Driven
Group Icon
Group: Honored
Posts: 2,624
Joined: 26-June 04
Member No.: 213





Excellent tut, Eddie!

Would love to give it a try, but I don't have SWiSH smile.gif

Nice work thumbsup.gif
 
+Quote Post  Go to the top of the page
Zaigham
post May 7 2005, 01:00 AM
Post #5


13Dots' Friend!
Group Icon
Group: *Premier*
Posts: 501
Joined: 13-July 04
From: Pakistan
Member No.: 400





Excellent job Eddie thumbsup.gif

Nice, well explained, easy to follow tutorial smile.gif

Thanks for sharing,

Regards,

Zaigham
 
+Quote Post  Go to the top of the page
zasul
post May 10 2005, 03:56 AM
Post #6


New Member
Group Icon
Group: Member
Posts: 3
Joined: 11-March 05
Member No.: 2,552





i think i got his flesh caught in the zipper good job bravo ma eddi
 
+Quote Post  Go to the top of the page
Eddie_K
post May 10 2005, 05:42 AM
Post #7


Hush now, I'm thinking...
Group Icon
Group: *Premier*
Posts: 3,977
Joined: 25-May 04
From: Heaven
Member No.: 47





Thank you bigwink.gif

Eddie
 
+Quote Post  Go to the top of the page
Daisy__
post May 10 2005, 12:27 PM
Post #8


Comp Winner
Group Icon
Group: *Premier*
Posts: 104
Joined: 3-January 05
Member No.: 1,655





I think that you explained very well this tutorial and you worked very clean and organised...
Very nice and realistic design! wub.gif

This post has been edited by Daisy__: May 10 2005, 12:29 PM
 
+Quote Post  Go to the top of the page
Eddie_K
post May 10 2005, 05:49 PM
Post #9


Hush now, I'm thinking...
Group Icon
Group: *Premier*
Posts: 3,977
Joined: 25-May 04
From: Heaven
Member No.: 47





Thank you dear. I know someone that was close to me when I created it LOL

Eddie
 
+Quote Post  Go to the top of the page
RedDragon
post May 11 2005, 05:04 AM
Post #10


insert coin
Group Icon
Group: Main Team
Posts: 5,344
Joined: 24-May 04
From: Maastricht
Member No.: 35





cool tut Eddie smile.gif

thx a lot!
 
+Quote Post  Go to the top of the page

6 Pages V   1 2 3 > » 
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 9th February 2010 - 01:34 AM
Kamala Harris | Cheat Codes | Freelance Jobs | Free Online Greeting Cards : Meme4u | Sports 2007