Choose fontsize:
Welcome, Guest. Please login or register.
Did you miss your activation email?

 

Pages: [1]   Go Down
  Print  
Author Topic: Sliding Effect  (Read 27249 times)
0 Members and 1 Guest are viewing this topic.
Tutorial Writer
*

Karma: 4
Gender: Male
Posts: 1,116



View Profile WWW
« on: September 26, 2005, 08:57:22 PM »
[h1]Sliding Effect[/h1]

Okay, here's how you make a 'sliding' effect, where the 'dot' or unit slows to a stop, and speeds up to a top speed. It's very easy, and all it requires is a few lines of code, and, of corse, my favorit little 20x20 dot ^_^, but with Full Range Movement

Okay, let's get the basics done again:
  • Open Flash
  • Go into properties and make it look like this:
  • Make the 20x20 circle like this:
  • Press F8 to convert it to a MovieClip
  • Make the Convert Box look like this:
Okay, now we've got a 400x400 Movie, frame rate of 30, background of solid white, and a MovieClip. Now we've got to add these actions to the MovieClip:
Code:
onClipEvent (load) {
xs = 0;
ys = 0;
s = 0;
_rotation = 0;
}
onClipEvent (enterFrame) {
_x += xs;
_y -= ys;
if (Key.isDown(65)) {
_rotation -= 5;
}                 
if (Key.isDown(68)) {
_rotation += 5;
}               
if (Key.isDown(87)) {
s += 0.5;
xs = s*Math.sin((_rotation*Math.PI)/180);
ys = s*Math.cos((_rotation*Math.PI)/180);
}           
if (_x<=10) {
_x += s;
}               
if (_x>=390) {
_x -= s;
}             
if (_y>=390) {
_y -= s;
}             
if (_y<=10) {
_y += s;
}           
if (s>0 && Key.isDown(87) != true) {
s -= 0.5;
xs = s*Math.sin((_rotation*Math.PI)/180);
ys = s*Math.cos((_rotation*Math.PI)/180);
}         
if (s<0) {
s = 0;
}         
if (s>5) {
s = 5;
}
}
Okay, nice and long, like normal, so let's take it bit by bit!
Code:
onClipEvent (load) {
xs = 0;
ys = 0;
s = 0;
_rotation = 0;
}
Same as the Full Range Movement Tutorial, set's a few variables xs = the _x speed; ys = _y speed; s = speed; _rotation = the MovieClip's rotation.

Code:
onClipEvent (enterFrame) {
_x += xs;
_y -= ys;
Now here's a little different code, if you notice, I made it so it always is moveing, that is, the _x and _y location is always getting modified, so when you let go of the key, it will 'slide'.

Code:
if (Key.isDown(65)) {
_rotation -= 5;
}                 
if (Key.isDown(68)) {
_rotation += 5;
}   
Rotates the MovieClip according to the 'A' (65) and 'D'(68) keys.

Code:
if (Key.isDown(87)) {
s += 0.5;
xs = s*Math.sin((_rotation*Math.PI)/180);
ys = s*Math.cos((_rotation*Math.PI)/180);
}
When you press the 'W' key, it moves the MovieClip according to the direction it's facing, and increases 's', giving a speed up effect.

Code:
if (_x<=10) {
_x += s;
}               
if (_x>=390) {
_x -= s;
}             
if (_y>=390) {
_y -= s;
}             
if (_y<=10) {
_y += s;
The borders, same as my Full Range Movement Tutorial.

Code:
if (s>0 && Key.isDown(87) != true) {
s -= 0.5;
xs = s*Math.sin((_rotation*Math.PI)/180);
ys = s*Math.cos((_rotation*Math.PI)/180);
}
Here's the main part of the sliding effect, it's the script that makes it slow down to a stop, or slide. It makes sure that the 'w' key ISN'T down, and that 's' is greater then 0, then it takes 0.5 away form 's', and chages the 'xs' and 'ys' variables accordingly.

Code:
if (s<0) {
s = 0;
}         
if (s>5) {
s = 5;
}
}
And finally, we have the two if statements that say:
"If 's' is less then 0"
"'s' equals 0" which keeps s at 0 if it goes under

"If 's' is greater then 5"
"'s' equals 5" 's' will stay at 5 as a maximum speed, to keep it form going too fast.

Well, that's it, here's the final product:
Use W, A, D keys to move around.
<a href="http://www.graphicaddicts.net/ssj/sliding%20effect.swf" target="_blank">http://www.graphicaddicts.net/ssj/sliding%20effect.swf</a>

If you like this tutorial, please Click Here to register.

Click the link below to download the Flash file for this tutorial.
Sliding Effect FLA
« Last Edit: February 10, 2006, 05:50:43 PM by ssjskipp » Logged
Global Moderator
*

Karma: -8
Gender: Male
Posts: 1,170



View Profile
« Reply #1 on: September 27, 2005, 03:15:45 AM »
another nice tut dude
Logged
Tutorial Writer
*

Karma: 9
Gender: Male
Posts: 1,254


I'm mighty tighty whitey and I'm smugglin' plums.


View Profile WWW
« Reply #2 on: September 27, 2005, 08:46:15 AM »
Nice tut, man =]
Logged
Tutorial Writer
*

Karma: 4
Gender: Male
Posts: 1,116



View Profile WWW
« Reply #3 on: November 09, 2005, 10:38:49 PM »
=] More are on their way!
Logged
Regular
*

Karma: 0
Posts: 39

Graphic Addicts BEAST Member


View Profile WWW
« Reply #4 on: November 10, 2005, 06:22:47 PM »
That's really cool, but I dont have flash, where can I get it, preferably for free. Hahaha
Logged
Global Moderator
*

Karma: 13
Gender: Male
Posts: 1,080

A family kinda guy


View Profile WWW
« Reply #5 on: November 10, 2005, 07:25:17 PM »
for free?Huh hahaha you wish.

Nothing in life is free, SKETCHi knows the best websites for buying software.
Logged
Administrator
*

Karma: 50
Gender: Male
Posts: 2,639



View Profile WWW
« Reply #6 on: November 10, 2005, 11:15:14 PM »
No I don't lol.. www.macromedia.com is where you can get Flash, but it won't be cheap. Get the free trial and see if you like it.
Logged
Tutorial Writer
*

Karma: 4
Gender: Male
Posts: 1,116



View Profile WWW
« Reply #7 on: November 13, 2005, 01:03:34 AM »
*agrees*, lol, although, some people may claim to find websites willing to sell Macromedia Flash (any version) for EXTREMELY low prices. I have yet to look into this, but I've seen as much as a 400$ discount on some sites =o, well, according to them =o!
Logged
Newbie
*

Karma: 0
Posts: 14

1+1 = 11


View Profile WWW
« Reply #8 on: September 30, 2006, 02:53:10 AM »
thx for the guide... ill try it Smiley
Logged
Tutorial Writer
*

Karma: 4
Gender: Male
Posts: 1,116



View Profile WWW
« Reply #9 on: October 02, 2006, 02:34:40 PM »
Heh, yeah, this is mainly to demonstrate that you can make an ease, of sorts, by manipulating a variable. Sort of like gravity and such, you just add to a variable, and it 'gains speed' as it goes.
Logged
Newbie
*

Karma: 0
Posts: 25

Graphic Addicts Member


View Profile
« Reply #10 on: October 18, 2006, 04:11:47 PM »
Lol nice tut dude!! Grin
Logged
Regular
*

Karma: 0
Gender: Male
Posts: 42

Pulse can you feel it


View Profile
« Reply #11 on: February 06, 2007, 09:31:09 AM »
Nice tutorial i just got flash and im trying to find out how to use it.
Flash is prity cool Wink
Logged
Tutorial Writer
*

Karma: 4
Gender: Male
Posts: 1,116



View Profile WWW
« Reply #12 on: February 15, 2007, 12:07:05 AM »
Thanks for comments all :3!
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:      

Flawsome [ In: 446 // Out: 2084 ] Pixel-Designz [ In: 1299 // Out: 3309 ] BioRUST [ In: 3322 // Out: 2811 ] SMF Topsites [ In: 0 // Out: 2349 ] Graphic Addicts Topsites [ In: 2688 // Out: 3852 ] Xtreme-Pixel [ In: 118 // Out: 1957 ] Glitch Seekers [ In: 543 // Out: 1803 ] Dr. Photoshop [ In: 1392 // Out: 1969 ]
Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC
Phobos design by Bloc | XHTML | CSS


Google visited last this page Today at 12:35:01 PM