| Welcome to Brackenwood. We hope you enjoy your visit. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
| Particle Tutorial; You know you want to. | |
|---|---|
| Tweet Topic Started: Jan 6 2006, 04:00 PM (608 Views) | |
| Mr. Jiggmin | Jan 6 2006, 04:00 PM Post #1 |
|
made of tulips
|
Welcome to the super and amazing particle effect tutorial! This tutorial assumes you have some general knowledge of actionscript. (loops, if statements, that kind of stuff) If you're saying "ActioningScripter wha??", then maybe here is a good place to start. This'll work on Flash MX 2004 and up. (If you work around the "getNextHighestDepth()'s" then I think It'll work on MX as well.) Step 1 - Drawing a rather small thing in a movie clip. 1.1 - Make a new movie clip and name it whatever you want. ![]() 1.2 - Draw your particle! Yay! Particle! Make sure that the crosshair is at the center of your particle! ![]() 1.3 - Right click on the move clip in your library, click linkage, then check the Export for ActionScript and Export in First Frame options. Enter "fireBall_mc" for the Identifier. ![]() Step 2 - Programmig. 2.1 - Put this code onto the first frame of the root timeline.
Step 3 - Explaining the programming. 3.1 - This line of code makes a new array that will store the name of all of the particles later on.
3.2 - rotSpeed is how fast the particles turn towards the mouse, move speed is how fast the particles move in the direction they're facing, and maxParticles is the maximum number of particles that can be on stage at one time.
3.3 - The pressed variable keeps track of weather or not the mouse is pressed. False for up, and true for down.
3.4 - These handy variables are the numbers that convert radians to degrees and visa versa.
3.5 - When the mouse button goes up, pressed becomes false. When the mouse button goes down, pressed becomes true. This bit of code makes it so.
3.6 - Everything inside the onEnterFrame runs every frame, which in mine is 30 times per second.
3.7 - If the mouse is pressed and there are less than the maximum amount of particles on the screen, it makes a new particle via attachMovie(). The name of that movie clip is then stored in the variable "m". The x and y positions of the particle are set to the position of the mouse, and the particles rotation is set to a random number between -180 and 180. Finally, the particles name is added to the end of particleArray.
3.8 - If the mouse is not pressed and there are still particles on the stage, it removes a particle from the beginning of particleArray.
3.9 - This is a loop that moves all of the particles each frame. The first line sets the loop up to go through every name in particleArray, so all of this code is run once for every particle. The first thing the loop does is name fBall what ever the name in particleArray is, because it's a pain to type "particleArray[j]" all the time. Then it figures out the angle between the mouse and the particle, and turns the particle towards the mouse. Finally, the particle is moved forward in the direction it's facing by converting it's rotation into radians and multiplying the cos and sin of that by the moveSpeed you entered up at the top.
Test it, and hopefully it will work. This is pretty bare bones, you can add some pizzazz if you're feeling it. Here's the finished product: (click and drag) Tell me what I need to explain more or could do better… I suck at explaining/teaching, and that’s something that I'm trying to overcome. |
![]() |
|
| ItsaMystery | Jan 7 2006, 09:50 AM Post #2 |
|
Brackenwood Lightweight
|
Wow, thanks! I'll definetely try this one out
|
![]() |
|
| TheEYE | Jan 7 2006, 11:51 AM Post #3 |
![]()
Lurys Fey Daemyt
![]()
|
Awesome tut Jiggs! Thanks for taking the time to do it man!
|
![]() |
|
| -hashbrown- | Jan 7 2006, 12:06 PM Post #4 |
|
Brackenwood Lightweight
|
thats really nice |
![]() |
|
| mechablob | Jan 7 2006, 07:31 PM Post #5 |
|
What'cha doing?
|
wow. sexy tip jiggman. I'll use this one for a signature maybe...
|
![]() |
|
| juggleballz | Jan 7 2006, 11:44 PM Post #6 |
|
I'm loose, full of juice and ready for use!
|
wow jacob that tut is cool man. i think it wud be cool for a flash game, where u click on ur charatcer and it charges up a particle fire ball, once fully charges drag the cursor towards the enemy, and using hit tests u cud make them act like mini fire balls. i dunno, just a suggetion. As for explaining, i think ya did okay man. still complicated in areas. what do u mean by RADIANS? , like the radius but plural? thanks for the tut. ill post mine up when i get a chance to make one. Im studying for a big dirty Javascript and XML exam at moment.
|
![]() |
|
| Vector | Jan 8 2006, 09:53 AM Post #7 |
|
Resident Actionscript Guru ♂
![]()
|
Degrees and radians are two different methods for measuring rotation. The following image is a diagram of the values of radians, starting at the right and going anti-clockwise. ![]() Basically, the only reason we do radians conversion is in order to use Math.sin and Math.cos (because they work in radians, not degrees.) |
![]() |
|
| Mr. Jiggmin | Jan 8 2006, 03:11 PM Post #8 |
|
made of tulips
|
Ungg... Once upon a time I had all of those things on the outside of the circle memorized. My Pre-cal teacher was insane about those. He was insane about a lot of things, but he was by far the funniest person I have ever known.
Not a bad idea... Smells like a Kimblis the Blue II spell to me. Anywho, Hopefully this'll help a few people with the AS competition. |
![]() |
|
| Vector | Jan 8 2006, 03:37 PM Post #9 |
|
Resident Actionscript Guru ♂
![]()
|
Nice. The values aren't really that hard to remember, and are actually quite easy to figure out. Half way around the circle (from right to left, anti-clockwise) is PI. So directly up is half of that (PI / 2), Half of that is PI / 4 which is 45 degrees, etc. It's just a matter of figuring out where ya neeed to get to. If you were referring to the root 3 on 2, etc, we have to know those for General maths, Maths methods and Specialist maths, they crop up all the time. |
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Actionscript · Next Topic » |












5:11 AM Jul 12