Topic closed
This is a response to a request for a basic flash game making tutorial.
For any of this to be useful to you you must be familiar with the flash program and know how to make basic animations.
If you don't have flash you can download trials at these locations. The trials are good for 30 days.
http://www.soft32.com/download_353.html flash mx
http://www.click-now.net/download/Macromedia_Flash.htm flash 8
First of all I am going to tell you have to make sprites for your flash.
Make a drawing, right click the drawing and covert it to a symbol. When asked what type of symbol you want chose Movie Clip.
Ok now that you have your movie clip symbol you can put code in it. But first give the symbol an instance name of hero. This can be done by clicking the symbol, then clicking the properties tab and the bottom and then entering the name into a little text box that will have the words <Instance Name>. Once you have your movie clip named you can begin coding.
copy and paste the following code into the movie clip.
onClipEvent(enterFrame){ if(Key.isDown(Key.LEFT)){ _x-=10;} if(Key.isDown(Key.RIGHT)){ _x+=10;} if(Key.isDown(Key.UP)){ _y-=10;} if(Key.isDown(Key.DOWN)){ _y+=10;} }
This is the scratch equivalent of this script.
[blocks]
<when green flag clicked>
<forever>
<if> <key[ left arrow ]pressed?>
<change x by( -10
<end>
<if> <key[ right arrow ]pressed?>
<change x by( 10
<end>
<if> <key[ up arrow ]pressed?>
<change y by( 10
<end>
<if> <key[ down arrow ]pressed?>
<change y by( -10
<end>
<end>
[/blocks]
Now you can press ctrl+enter to compile your flash program. If you did everything correctly your movie clip symbol should be able to move with the arrow keys.
Now for the breakdown of the code.
onClipEvent(enterFrame){}
Ok this is a declaration of a clip event. Clip events are used to make code inside movieclips run. The clip event I choose was enterFrame and what that does is it executes the code inside the brackets every frame. So if you have your frame rate set to 30 then the code inside the brackets will execute 30 times a second. enterFrame is the most commonly used clip event.
if(Key.isDown(Key.LEFT)){
_x-=10;}
This is our if statement that moves the movie clip. It check to see if the condition inside the brackets is true and if it is then the executes the code in the squiggly brackets {}. This particular if statement is checking if the left arrow key is down and it is then the movie clip moves 10 units left.
This part
{
_x-=10;}
Means that the _x position of the movie clip is going to be equal to itself minus 10. The -= used to change the value and there and there are different kinds of these symbols.
Here is a small list of some of the different ones
-= the value equals itself minus another number
+= the value equals itself plus another number
*= the value equals itself times another number
/= the value equals itself divide by another number
Ok, now that we have our moving movie clip and we understand what the code in it does we are going to make a simple enemy.
So make an movie clip symbol like you did before and give it an instance name of enemy.
Now that we have our enemy we should set it up so that we lose life when the hero movie clip touches it. So what we have to do is declare a variable on the frame that your movie clips are on.
Insert the following code into the frame
var life=100;
what we just did was create a variable called life and assigned it a value, which in this case is 100.
Now go on the enemy sprite and insert the following code
onClipEvent(enterFrame){ if (this.hitTest(_root.hero)){ _root.life-=3; } }
This is the scratch equivalent of that script
[blocks]
<when green flag clicked>
<forever>
<if> <touching[ hero
<change{ life }by( -3
<end>
<end>
[/blocks]
Now for the breakdown of the code. I will assume you already know what the onClipEvent(enterFrame) does.
if (this.hitTest(_root.hero))
Yes, this is an if statement. Inside the if statement we are preforming a hitTest on the hero movie clip. In this hitTest the "this" refers to the sprite the code is on (the enemy sprite) and inside the brackets we are referring to the hero sprite we made. The reason we need a _root. before the sprite name is because whenever you are referring to something that is outside of the movie clip you must first put _root. before the value or symbol you are referencing.
_root.life-=3;
As I just said since this variable is not part of the movie clip (it should be in a frame in the main timeline) we need to reference it using _root.. We are taking 3 units away from the life variable.
Now for the last part, displaying the variable. This is pretty simple, just put a text box on the stage, and in the properties tab site it to dynamic, and in the var: box put in
_root.life
If you want to learn more check out these links
http://www.newgrounds.com/portal/view/366346
http://www.newgrounds.com/portal/view/344206
http://www.newgrounds.com/bbs/topic/229808/50
http://www.flashkit.com/tutorials/
http://www.actionscript.org/
http://www.kirupa.com/
Last edited by archmage (2008-08-11 15:45:52)
Offline
Hey archmage! Cool that you are presenting flash basics here. I think it provides a good way for learning new, more advanced programming languages for scratch-ers.
You might want to put youre code between [ code ] and [/ code] tags. It would be a bit more easyer to erad it.
And what about showing how it works in scratch?
Like
onClipEvent(enterFrame){ if (this.hitTest(_root.hero)){ _root.life-=3; } }
[blocks]
<forever>
<if><touching[ hero
<change{ life }by( -3
<end>
<end>
Offline
JSO wrote:
Hey archmage! Cool that you are presenting flash basics here. I think it provides a good way for learning new, more advanced programming languages for scratch-ers.
You might want to put youre code between [ code ] and [/ code] tags. It would be a bit more easyer to erad it.
And what about showing how it works in scratch?
LikeCode:
onClipEvent(enterFrame){ if (this.hitTest(_root.hero)){ _root.life-=3; } }[blocks]
<forever>
<if><touching[ hero
<change{ life }by( -3
<end>
<end>
Yeah putting in those things would probably be a good idea. I'll add those things soon.
Last edited by archmage (2008-06-17 10:30:14)
Offline
Great tutorial!
Offline
Bobby500 wrote:
Great tutorial!
Did you make anything using the tutorial? If so it would be awesome if you could post a link to the flash file.
Offline
dingdong wrote:
flash doesn't look to hard from this perspective because its about as much code as scratch for that, Python will be hard for me I'm pretty sure
Remember, this is the basics. I made it keeping in mind that the people reading it are beginners
You should try making a flash program using this tutorial. If you get good then you can try making flash games.
Offline
Now I really wanna see what's wrong with my computer. If I could just fix 1 thing, I'd be able to get Flash
Offline
dingdong wrote:
nah, right now I've got to learn Python and make some awesome 3D game
You can't really say flash is easy if you don't even attempt to code in it. :S
Just try it, the language is similar to scratch and making this program in the tutorial will probably take 10 minutes of your time.
Offline
And if I could get it, I actually think I'd be good at it, since I knew what everything meant before you explained it.... or maybe that is ll of my "studying" in HTML and stuff to help me know what it means (or Scratch [key up change Y, Key left hange X])
Offline
Bluestribute wrote:
And if I could get it, I actually think I'd be good at it, since I knew what everything meant before you explained it.... or maybe that is ll of my "studying" in HTML and stuff to help me know what it means (or Scratch [key up change Y, Key left hange X])
HTML is VERY different from action script and won't help you learn AS. Scratch will probably make you understand better. If you do learn flash action script well you will become a much better coder than if you were to stick with scratch.
Offline
archmage wrote:
Bluestribute wrote:
And if I could get it, I actually think I'd be good at it, since I knew what everything meant before you explained it.... or maybe that is ll of my "studying" in HTML and stuff to help me know what it means (or Scratch [key up change Y, Key left hange X])
HTML is VERY different from action script and won't help you learn AS. Scratch will probably make you understand better. If you do learn flash action script well you will become a much better coder than if you were to stick with scratch.
But I mean more like it looks familiar with all those symbols and periods and stuff. And I'm slef-eaching myself HTML, Javascript, PHP, etc (whatever w3schools has to offer)
Offline
Bumping this for me
Offline
Awesome tutorial archmage! This is especially useful for me since I am getting flash some time this week or next week. Thanks!
Offline
Cyclone103 wrote:
Awesome tutorial archmage! This is especially useful for me since I am getting flash some time this week or next week. Thanks!
Remember that this is just for AS2. The newest version of flash features AS3 which is way more efficient. I reccomend trying out both languages though.
Offline
archmage wrote:
Cyclone103 wrote:
Awesome tutorial archmage! This is especially useful for me since I am getting flash some time this week or next week. Thanks!
Remember that this is just for AS2. The newest version of flash features AS3 which is way more efficient. I reccomend trying out both languages though.
I tried AS3, and this seems easier.
Offline
Wow thats great! I see how the coding is similar (mathematically to equations necessary). I was thinking a couple days ago how <change variable by x> is the equivelant to <set variable to variable+x>. I have never really tried any advanced coding but maybe some day i could check it out.
Offline
Archmage my computer detected a virus on the website with imageupload.com Im pretty sure its just the actual website trying to download a program but I just wanted to let you know.
Offline
Hmmm... I wish I had flash. We're doing some pretty basic animations using Flash at a summer camp called ESQ (Engineering Science Quest) at our local university. I actually just got back a few hours ago (it's only during the day as our parents probably don't want us programming ALL day)
Offline
coolstuff wrote:
Hmmm... I wish I had flash. We're doing some pretty basic animations using Flash at a summer camp called ESQ (Engineering Science Quest) at our local university. I actually just got back a few hours ago (it's only during the day as our parents probably don't want us programming ALL day)
You can try the trial versons, they are good for 1 month.
Last edited by archmage (2008-08-05 22:08:27)
Offline
http://board.flashkit.com/board/showthread.php?t=774054
I posted the actually code there. I need help with a hitTest, and since this topic is "actionscript 2.0", I thought I could post it. Anyone here know the answer? That link has what I'm trying to do
Offline
Nevermind. I fugred it out. I just put a:
if (hitTest(_root.poly)){
this._X= random(500)+1
_Y= 500}
Not very clean way, but it is working
Offline
Bluestribute wrote:
Nevermind. I fugred it out. I just put a:
if (hitTest(_root.poly)){
this._X= random(500)+1
_Y= 500}
Not very clean way, but it is working
You are doing it wrong. Don't put anything inside the brackets on your random function, and the x and y properties should be in lower case and using "this" is not necessary because simply putting _x will refer to the x of the sprite that the code is on.
like this
if (hitTest(_root.poly)){
_x=(Math.random()*500)+1;
_y=500;
}
Also, the newgrounds flash forum is very active and you will probably get quick responses there.
Offline
archmage wrote:
Bluestribute wrote:
Nevermind. I fugred it out. I just put a:
if (hitTest(_root.poly)){
this._X= random(500)+1
_Y= 500}
Not very clean way, but it is workingYou are doing it wrong. Don't put anything inside the brackets on your random function, and the x and y properties should be in lower case and using "this" is not necessary because simply putting _x will refer to the x of the sprite that the code is on.
like this
if (hitTest(_root.poly)){
_x=(Math.random()*500)+1;
_y=500;
}
Also, the newgrounds flash forum is very active and you will probably get quick responses there.
But that way is working. I'm using 2.0 . In fact, it is very effective too, placing the spikes randomly each time.
Offline
Topic closed