Flash game creation tutorial – part 3
March 14th update: part 5.3 released.
March 3rd update: part 5.2 released.
February 9th update: part 5.1 released.
December 31st update: 5th part released.
December 23rd update: 4th part released.
Here we go with the 3rd step.
Remember to read 1st and 2nd part if you are new to this tutorial, and let’s go.
We left our hero colleting coins, so next step will be…
The score
Scoring system consist in a variable set to 0 (zero) when the game starts and some events that may increase/decrease the score.
In this case, you get 1 point when you collect a coin, and lose 2 points when you crash into a wall.
Hall I have to do is initializing a variable in the root with a single action
1 | score = 0; |
And then in the hero movieclip
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | onClipEvent (load) {
yspeed = 0;
xspeed = 0;
wind = 0.00;
power = 0.65;
gravity = 0.1;
upconstant = 0.75;
friction = 0.99;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xspeed = xspeed-power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed = xspeed+power;
}
if (Key.isDown(Key.UP)) {
yspeed = yspeed-power*upconstant;
}
if (Key.isDown(Key.DOWN)) {
yspeed = yspeed+power*upconstant;
}
xspeed = (xspeed+wind)*friction;
yspeed = yspeed+gravity;
_y = _y+yspeed;
_x = _x+xspeed;
_rotation = _rotation+xspeed;
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
_root.score -=2;
}
if (_root.coin.hitTest(this.hero_hit)) {
_root.coin._x = Math.random()*400+50;
_root.score ++;
}
} |
Look at lines 33 and 37… as said, you get one point when you collect a coin and lose 2 points when you hit the wall.
A dynamic text in the main scene displays the score.
Sooooo easy… now let me introduce you the main event for this tutorial… the environment…
We can have different kinds of environment… let’s start with the easiest.
The killing fixed environment
The killing fixed environment is a deadly part of the stage that does not move, such as a spike.
So I created a new movieclip called environment and instanced as environment and placed in the stage.
You choose how to detect the collision, with the center of the hero or with the hero_hit shape (time to read part 2 if you do not understand what I am talking about).
Just remember you game does not have to be too easy or too hard.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | onClipEvent (load) {
yspeed = 0;
xspeed = 0;
wind = 0.00;
power = 0.65;
gravity = 0.1;
upconstant = 0.75;
friction = 0.99;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xspeed = xspeed-power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed = xspeed+power;
}
if (Key.isDown(Key.UP)) {
yspeed = yspeed-power*upconstant;
}
if (Key.isDown(Key.DOWN)) {
yspeed = yspeed+power*upconstant;
}
xspeed = (xspeed+wind)*friction;
yspeed = yspeed+gravity;
_y = _y+yspeed;
_x = _x+xspeed;
_rotation = _rotation+xspeed;
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 50;
_y = 50;
}
if (_root.environment.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 50;
_y = 50;
}
} |
Lines 34-39 do the routine that checks collision between the hero and the environment
This is useful if you want to place objects on the stage that may kill the hero.
Sometimes, the environment should move.
The killing tweened environment
I am calling “tweened environment” an object that always moves along a path… such as a sliding wall or something similar.
The actionscript, obviously, is the same as above, the only change is to the environment object, that now has a tweening motion. You’ll see it better when you will download the sources, at the end of this tutorial.
The only thing I want you to know is: for a better result, the number of pixels the environment moves at every frame should be an integer. I mean that if you want to move your environment by 150 pixels, be sure that dividing the pixels for the numbers of frames you have an integer number.
In my case, I move the environment by 150 pixels in 75 frames… 150/75 = 2 (integer) pixels/frame.
It’s not a mandatory rule, and in most cases you will experience it is impossible to achieve such integer numbers, while you can do it, well, do it.
Sometimes we want the hero to interact with environment, so I will explain howo to get…
The triggered environment
Let’s suppose to have a wall that moves very fast… making our life so hard… we should let the player decide to cross the wall, risking his life, or turn off the “engine” that moves the wall, for example pushing a button or pulling a lever.
In this new movie I created a new object named as trigger and instanced as trig, with the shape of a lever.
Then I added some actionscript to the environment, that is no longer tweened.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | onClipEvent (load) {
dir = 4;
moving = 1;
}
onClipEvent (enterFrame) {
if (moving) {
_y += dir;
if (_y>300) {
dir = -4;
}
if (_y<50) {
dir = 4;
}
}
} |
This is a very simple movement routine… I will explain more complex routines later in the tutorial, but at the moment I only want a wall to cross the stage up and down, and the hero to get the trigger to stop it.
The script is very simple, just take a look at the moving variable. You can see that the environment will move by 4 pixels (integer…) upwards or downwards as long as the moving variable is set to 1.
How can we stop it?
With lines 40-43 of the hero’s actionscript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | onClipEvent (load) {
yspeed = 0;
xspeed = 0;
wind = 0.00;
power = 0.65;
gravity = 0.1;
upconstant = 0.75;
friction = 0.99;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xspeed = xspeed-power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed = xspeed+power;
}
if (Key.isDown(Key.UP)) {
yspeed = yspeed-power*upconstant;
}
if (Key.isDown(Key.DOWN)) {
yspeed = yspeed+power*upconstant;
}
xspeed = (xspeed+wind)*friction;
yspeed = yspeed+gravity;
_y = _y+yspeed;
_x = _x+xspeed;
_rotation = _rotation+xspeed;
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 450;
_y = 50;
}
if (_root.environment.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 450;
_y = 50;
}
if (_root.trig.hitTest(_x, _y, true)) {
_root.trig.gotoAndStop(2);
_root.environment.moving = 0;
}
} |
If the hero hits the trigger (as explained before, you will decide the type of collision checking later when you will test the entire game), the trigger frame is moved to 2 displaying a pulled lever and the moving variable is set to 0.
In this case, the actionscript of the environment won’t enter in the if condition and the environment will stop.
Possibile applications of this routine are almost infinite: imagine buttons that stops dangerous object moving, levers that reveals hidden zones with treasures, and so on.
We will discover all those options when the game will be in progress… remember that at the moment I am just showing you the basics.
Talking about basics, let’s see a type of environment that as far as I know is not included in ball:revamped (of course we always have to try to improve existing concepts).
The undeadly environment
I want an environment that does not kill the hero, but that changes some behaviours… imagine a stage that is partially flooded.
You have water in the stage, and your hero underwater movements will be more difficult.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | onClipEvent (load) {
yspeed = 0;
xspeed = 0;
wind = 0.00;
power = 0.65;
gravity = 0.1;
upconstant = 0.75;
friction = 0.99;
sunken = 0;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xspeed = xspeed-power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed = xspeed+power;
}
if (Key.isDown(Key.UP)) {
yspeed = yspeed-power*upconstant;
}
if (Key.isDown(Key.DOWN)) {
yspeed = yspeed+power*upconstant;
}
xspeed = (xspeed+wind)*friction;
yspeed = yspeed+gravity;
if(sunken == 0){
_y = _y+yspeed;
_x = _x+xspeed;
}
else{
_y = _y+(yspeed/5);
_x = _x+(xspeed/3);
}
_rotation = _rotation+xspeed;
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 50;
_y = 50;
}
if (_root.environment.hitTest(_x, _y, true)) {
sunken = 1;
}
else{
sunken = 0;
}
} |
Line 9 has a new variable that determines if the hero is underwater or not.
Then, when it’s time to update hero’s position according to gravity, speed, and so on…
Lines 26-33 checks if the hero is underwater or not. If it’s underwater, movements are reduced by 5 vertically and by 3 horizontally.
Note: I said movements are reduced, not the speed! This means that when you will pop out of the water, you have to pay attention to your speed. I want the player to move carefully when underwater, not simply have slower (easier) movements.
Now let’s imagine to have some special object on the stage. If the hero collects such object will raise the score, but the entire environment will get harder.
The playing environment
A little game covering some of the thems we discussed until now.
You have to score as much as you can. As seen before, you get 1 point when you collect a coin, you lose 2 points when you hit the walls and 1 point when you hit the environment.
Easy? Not at all… I forgot to tell you the environment moves, and the higher your score, the faster the movement.
The actionscript on the first frame is
1 | score = 0; |
You may ask: can’t you put this line in the hero onCLipEvent(load)?
Yes, I could, but you will see why I put it there when we will learn how to move around levels.
Anyway, in the environment object we have the actionscript:
1 2 3 | onClipEvent (enterFrame) {
_rotation=_rotation+0.25+_root.score*0.25;
} |
Do you see? the environment rotation speed increases as long as your score increases. So bad!
Finally, the hero actionscript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | onClipEvent (load) {
yspeed = 0;
xspeed = 0;
wind = 0.00;
power = 0.65;
gravity = 0.1;
upconstant = 0.75;
friction = 0.99;
_root.coin._x = Math.random()*400+50;
_root.coin._y = Math.random()*250+50;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xspeed = xspeed-power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed = xspeed+power;
}
if (Key.isDown(Key.UP)) {
yspeed = yspeed-power*upconstant;
}
if (Key.isDown(Key.DOWN)) {
yspeed = yspeed+power*upconstant;
}
xspeed = (xspeed+wind)*friction;
yspeed = yspeed+gravity;
_y = _y+yspeed;
_x = _x+xspeed;
_rotation = _rotation+xspeed;
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 50;
_y = 50;
_root.score -= 2;
if (_root.score<0) {
_root.score = 0;
}
}
if (_root.environment.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 50;
_y = 50;
_root.score -= 1;
if (_root.score<0) {
_root.score = 0;
}
}
if (_root.coin.hitTest(this.hero_hit)) {
_root.coin._x = Math.random()*400+50;
_root.coin._y = Math.random()*250+50;
_root.score++;
}
} |
Nothing new, just a check to the score to prevent it to be less than zero.
If you want, drop a comment with the highest score you achieved. I bet you won’t easily score more than 15.
Remember to give me feedback and suggestions.
Download the examples source code and move to the 4th part
They can be easily customized to meet the unique requirements of your project.
140 Responses to “Flash game creation tutorial – part 3”
Leave a Reply
Trackbacks
-
Flash game creation tutorial - part 1 at Emanuele Feronato on
December 6th, 2006 2:02 pm
[...] December 6th update: 3rd part released. November 18th update: 2nd part released. [...]
-
Flash game creation tutorial - part 4 at Emanuele Feronato on
December 23rd, 2006 6:27 pm
[...] Read steps 1, 2 and 3 if you’re new to this tutorial, then follow this one. [...]
-
Flash game creation tutorial - part 5 at Emanuele Feronato on
February 9th, 2007 6:58 pm
[...] Read steps 1,2,3 and 4 and you’re ready. [...]
-
Flash game creation tutorial - part 2 at Emanuele Feronato on
February 9th, 2007 7:01 pm
[...] February 9th update: part 5.1 released. December 31st update: 5th part released. December 23rd update: 4th part released. December 6th update: 3rd part released. [...]
-
Brettcr » Blog Archive » Programming Tutorials / Game Making Check Video Description download videos off you tube on
May 12th, 2008 11:43 pm
[...] Flash Actionscript Game Making Tutorialshttp://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/… [...]
-
Elise » Programming Tutorials / Game Making Check Video Description convert youtube video to dvd on
May 19th, 2008 4:27 am
[...] Flash Actionscript Game Making Tutorialshttp://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/… [...]
-
reducedoverlarge » Trailer for the upcoming Echo Wall climbing film on
October 8th, 2008 7:32 am
[...] Flash Actionscript Game Making Tutorialshttp://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/… [...]
-
forfreebigger » Diving with Sharks at the Chumphon Pinnacles, Koh Tao Thailand on
October 9th, 2008 2:19 pm
[...] Flash Actionscript Game Making Tutorialshttp://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/… [...]
-
discountsize » 7 Tips for a Fun Filled Family Holiday Posted By : Johnn on
November 12th, 2008 11:32 am
[...] Flash Actionscript Game Making Tutorialshttp://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/… [...]
-
Yourothermind » Blog Archive » Not a Flash game - Brent Knowles' Blog and Writing Software on
June 29th, 2009 9:16 pm
[...] Just doing some playing around with flash and am working my way through the solid tutorial by Emanuele Feronato. [...]
- Create incredible particle effects with Partigen 2
- PixelBlitz AS3 game framework
- Being a geek in Venezuela
- Box2D tutorial for the absolute beginners – revamped
- Triqui’s Picks #16
- Are you ready for this?
- Box2DFlash 2.1a released – what changed
- Get detailed statistics about your Flash game with SWFStats
- Games that Challenge the World Come2Play contest – $8,000 in prizes
- Triqui’s Picks #15
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Create a flash artillery game - step 1
- Triqui MochiAds Arcade plugin for WordPress official page
- Flash game creation tutorial – part 5.2 (4.87/5)
- Create a flash artillery game – step 1 (4.78/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a survival horror game in Flash tutorial – part 1 (4.73/5)
- Flash game creation tutorial – part 3 (4.73/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 2 (4.70/5)
- Create a flash artillery game – step 2 (4.70/5)
- Flash game creation tutorial – part 1 (4.69/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)

(40 votes, average: 4.73 out of 5)



Hmmm… I know this is a begginer’s question to ask, and I’ll admit to being one, but how do I get two instances to group together and stay together during the “game”? I’ve tried many different ways, but they never work, I always end up leaving the square behind.
This is a very good tutorial. I have one comment to make however. On your last tutorial (Part 2) you told somebody it would be hard to make a bounce effect. Its actually very easy. Start by making two separate movie clips/instances for the walls, wall1 (floor and ceiling) and wall2, the right and left walls.
if (_root.wall.hitTest(_x, _y, true)) {
yspeed = yspeed*-1;
}
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = xspeed*-1;
}
Umm… woops. Redo.
if (_root.wall1.hitTest(_x, _y, true)) {
yspeed = yspeed*-1;
}
if (_root.wall2.hitTest(_x, _y, true)) {
xspeed = xspeed*-1;
}
Woho!
I scored 21 :D
i’m quite a newbie regarding flash, though i’d followed the tutorial quite easily (that’s a compliment) and managed to accomplish all the first steps but i can’t make a funcitonal score count. i’ve put the code correctly in the hero but i dont know what to do with the “score = 0;”, where to place it. (i mean, i don’t know how to initialaze a variable in the root) again, i’m new in this. sorry, hope to get ur answer
score done.
:)
I have the same problem Newbie had, i can’t get the score to function correctly…
I have “score = 0;” in the main frame, a dynamic text box in the main scene, and i have “_root.score ;” in the correct spot… still not sure why it isn’t responding.
great tutorial
couldnt get past 17 on that last 1
WOOHOO I SCORED 800 MILLION
hey can you make one with a guy gravity ground water and boxes to hop acros.
i beat ball revamped blblblblblblblblz
i am making lives in my game it works the same way as the score but it minus lives instead of score when it hits the walls. When the lives equals 0 i tried to make a code so that it takes it to a frame which says game over
but this code doesn’t work:
if (_root.lives=0) {
gotoAndStop(2);
}
can anyone help me???
im having the same problem with the ’score=0′ can anyone help me?? please where do i put it??? I cant use the scoring method! :(
in reply to sam:
your code:
if (_root.lives=0) {
gotoAndStop(2);
}
correct code:
if (_root.lives==0) {
gotoAndStop(2);
}
you should be checking if lives is equal to zero,
instead you had if, set lives set to zero.
honest mistake, every time you use an if statement with variables use 2 quals signs. it means “is equal to”
hope that cleared it up for you.
and as for the score newbies…
first frame, on the frame. put score=0;
then always refrence it with _root.score
it will work. full proof. if you can’t get it to work with that said, then go get a new hobbie.
Hi , how can i put the ”The killing tweened environment” , but also the ”Water” ?
Nice tutorial :) hope there will be more of thees, how to make a “mario style” platform game maybe? ^^
I’m not so good at this.. i could do everything exept for makeing the score board..
so if someone could tell me how to do(from the begining please) thanks!!
:)
Great tutorial!!!
woah, totally easy to learn, and you actually explain the action script, you are gifted at tutorials, and the root files for examples are a stroke of genius
i made a dynamic text block and gave it the instance name of score and gave put score = 0; in the actions menu of the main frame. i typed zero in it and tried the game and when i collide with the coin and walls the score does not increase or decrease what am i doing wrong can anyone help me
“gave put” is a typo woops i didnt put the word “put” in the script lol
wow been a while since hes replied to anyone
yus i scored 20
I got 16 on my first try!
where exactly do i put the score variable thing? (the first actionscript on the page)
i dont even get how to do the dynamic text box!?!? help!!!!!
I am having torouble with the score please help me by telling me exactly what i have to do with the score
This is to everyone who needs help with the score box.
Click the text tool in the tool panel and create a text box. In the properties area make sure the dropdown box is set to dynamic. In that same section you will see a text area labeled “var”. in there you type “score” because that is the name of the variable you want it to show. In the first frame of a layer (preferably the layer with the text box) enter the actionscript “score = 0;”.
If that doesn’t work, give me some slack. Post your problems and I’ll try to help. I am only 14. :-P
Oh yeah forgot.
Awesome tutorial!
Covers all actionscript problems.
Only thing is, I want to keep all my actionscript in the first frame of a layer called “action”.
How do I get the frame to recognize the onClipEvent (enterFrame) line for the hero MC?
im having a pronlem with the scoreing, i can make the text box and everything, but i cant find the var box =(, can any1 help?
This Tutorial is really great!!
Im 12 years old and I understand(most of) it!
But…
when I am Playing the game ive made, evrything goes in slomotion!!!
WHY MAAN WHYYYY!!!
To Mick. Mark your textbox and check the properties. Right under where you choose color and size of the letters, the “var” box is.
Help with inserting more “environments”
Been following this guide for a while. Been going well so far. Execpt one thing. How do i add more environments? If i copy the first one i had, it simply goes right through it.
;)
@confused pinguine
wat you have to do is increase the frames per second (fps) to 50
yeah i checked there but on my flash theres no var box there…maybe i’ll just upgrade to flash 8 ;).
i dont know if this was answered somewhere but alot of people were asking about the scoring. make a dynamic text box, give it a name then type this into action script.
_root.(text box name).text = “score: ” (variable name for score);
hope it helps
=\
– confused pengiun, just click on the stage, then open the properties bar at the bottom, there should be a box that says “FPS 12″, simply change the 12 to a higher number.
im using flash mx 6.0, so sry if you’re using a different version and this doesnt work
emanuele i mastered that spinning game i got 17!
Lol vasheeth you spelt beginner wrong
and mick flash 8, it rocks i suggest going for it
thx 4 ur help Helper monkey and trys everything!
I appriciate it man…
/\
(or however u spell it…)
Great tutorial, bad for beginner because you don’t explain very much.
how would i put in a variable showing the number of lives left and ‘game over’ -ing the game when the lives reach zero?
any help is appreciated
23 point!!!!!!!!
beat that!!!
In response to diamond drake:
your code:
if (_root.lives==0) {
gotoAndStop(2);
}
correct code:
if (_root.lives==0) {
_root.gotoAndStop(2);
}
im creating a trigger similer to the one used in the tutorial but i want to be able to stop and start the moving block the trigger affects effects I’m a complete begginner with flash but learning fast, any help you can give me is greatly apreciated.
Man, i can’t figure out the score thing either…i know im doin somethin wrong. if only i knew what… I put the score code in the frame, i make a dynamic text box with variable of score, and i put in the code in the hero. NOT WORKIN! When i veiw the movie, the score box doesn’t even start out with a zero in it!
oops, i meant instance! lol not variable
Hey i’m currently making a game (not like yours, but similar. and i was wondering, if theres a code, so that when the “hereo” touches a movie clip, it goes to the next scene?
Hi im all new to this actionscript stuff and so im confused. this is probably a really obvious answer but on the last game when i try to make the environment rotate, it doesn’t rotate from the middle, it always rotates from the left. can anyone help with this please?
Yay, after about an hour of mindlessly playing this game like a moron, I have finally achieved the coveted rank of 30, thus becoming the world class mindless game player
P.S. I can do the rubik’s cube in about 30 secs
So, I’ve read through the tutorials and I think they are pretty awesome. I’ve been tweaking numbers within the games, and I’ve noticed that I’m unable to make a solid object. I’ve been trying to make a solid ground or block that doesn’t kill the player, the player just can’t go through it. Mostly, I’ve been trying this with the ground. I’ve change the settings so that it doesn’t kill the player (commented out the change x and y positions) and I’ve changed the part where it changes the players speed, so rather than setting it to 0, it sets it to -(some number)*xspeed. Is there a specific number that I have to use that counters gravity and the player’s downward force? Like, for example, should I stop the players motion, than give them a gentle push upward?
im a little confused.
The score
Scoring system consist in a variable set to 0 (zero) when the game starts and some events that may increase/decrease the score.
In this case, you get 1 point when you collect a coin, and lose 2 points when you crash into a wall.
Hall I have to do is initializing a variable in the root with a single action
ACTIONSCRIPT:
1.
score = 0;
Where do i write the “score=0;” ?
im a little confused.
The score
Scoring system consist in a variable set to 0 (zero) when the game starts and some events that may increase/decrease the score.
In this case, you get 1 point when you collect a coin, and lose 2 points when you crash into a wall.
Hall I have to do is initializing a variable in the root with a single action
ACTIONSCRIPT:
1.
score = 0;
Where do i write the “score=0;†?
Score 14 xD
I know somethinks abouts programming (Div 2 xD), but flash (and any object oriented programming) is more complicated. Thanks for the tutorial, it’s very good ^_^.
why when i generate the SWF file of these tutorials, it doesnt get keyboard input dont work but when i use flashplayer, they work and gets my keyboards?
Emanuel, do u answer these questions?!
i realized by Clicking once on the browser, it gets my keyboard input, but why and how can i solve this bug/problem/”something that i dont want” ?
good tutorial for people who are intersted in making platform-type games. i dont think that this tutorial is suitable for newbs, cuz they cant learn math and variables at the beginning
This tutorial is great. I am having one problem, though, that other people seem to be having but that hasn’t been answered.
My hero cannot collect my coin. It passes right over it and the coin does not move. Does anyone know why that might be?
everybody listen!!!!!
the reason why your game is in slow motion is because your frame rate is not high enough
all you have to do is right click the screen
go to document properties
find frame rate(which is usually 12 for my PC ;D)
then change it to as fast as you want it
:O
i know its amazing isn’t it
o.O
For those having Trouble with the Score:
Make a text box on it’s own layer and resize it how you’d like. Click on the text box and look at the properties tab, make sure this is set to Dynamic, and set it’s variable to “score” (Which is NOT the box below where you select Dynamic, it’s below where you set the size of the text You might need to hit a little triangle shaped button on the bottom right of the properties box to see it).
THEN click on the first frame of that layer (in the frames above your work area, where you make new layers, click on the first dot under “1″). Now type the actionscript into that. “score = 0;”.
The problem you guys are probably having is the same that I did, not actually realizing what the variable box was.
Man, I only got 14. :( Oh well. Great tutorial, EF!!
BOOYAH i got 16 points XD even took a screen shot =p
lots of people have problem with that score thing
i have another “problem”
_root.coin._x = Math.random()*400+50;
_root.coin._y = Math.random()*250+50;
i think the numbers are so that the coin doesn’t get out of the screen, but how do u get hold of those numbers, is it trial and error?
because in part 2 only the _x is given and i tryed the same code only _x i changed in _y and sometimes my coin got out of the screen (not much)
anyone can explain ?
thanks already :)
i tweeked it a bit and now my guy is invincible and bounces off the wall and aims for the coins, plus every coin i get is worth some candy from a strangers van….
nah im playin, pretty good tutorial though
Yay! I got a 31! I spent about an hour playing though… Anyways, great tutorial! I’m learning a lot.
yer me to sorry i’m probably missing something obvious its just the score i dont quite get :(
OK. I have followed everyones advice, step by step. I put “score” in the variable box. And I put “score = 0;” into the frame, and I have done it about 300 times and still NOTHING!!!
I am literaly going insane. Help
hey
the tutorial was great and i got everything working and even the score goes up when the coin it touched BUT it doesnt stay after a split second the score goes back to 0 any idea??
your site is the best action script site i have ever seen. i have given it to all my friends, we are making an rts, like age of empires, can you help?????
Cool. I love your site.
Could you continue with your tutorial and help us making more interactive games, something like super-mario games?
ive got a better idea, i can make custom lives but its more difficult that what you want…
newb question but i cant pick up my coin and i have triple checked the code and its the same… any suggestions
I have had quite a few errors, im the same as confused teenager.
I think you need to be more spesific on where the code in question goes. Do all the codes go in the action script for the hero? Or do you put the coin code in the action script for the coiin itself,
CoNfUzzLeD
Motherload.
Make a treasure picture(not too big) and convert it to a MC, and give it the isntance of motherload,put in the following on the place where the “trigger”AS,
if (_root.trig.hitTest(_x, _y, true)) {
_root.trig.gotoAndStop(2);
_root.motherload._x = 50
_root.motherload._y = 50
}
if (_root.motherload.hitTest(this.hero_hit)) {
_root.motherload._x = -1000
_root.motherload._y = -1000
_root.score += 700
_root.motherload.gotoAndStop(2);
}
you get a motherload of points at 50 x and 50 y when you hit the trigger.
Made by me.
And inside the treasure MC, add a stop script to the first frame, make a other empty frame in it, and put in same AS.
GOININSANE!!!!
be sure to have a zero put int he text of ur dynamic text box,else it doesnt work.
Sometimes Emanuale forgot the coin scripts and more.
on the “water” example my charecter always seems to be “under water” or sunken, any help?
THis is the best tutorial i have ever had ,I have advice instead of writting
_y = _y + yspeed or yspeed = yspeed + gravity
& every thing like that Can also be written as
_y +=yspeed and yspeed+=gravity
Need Help I am Trying to make the game like this one http://www.addictinggames.com/maxdirtbike.html
But Problem Is this tutorial do not Explain Rotation And hittest do not work with curve objects So plsz Reply plzzzzzzzzzzzzzzzzz
your tutorials are very good but i cant seem to open the FLA files, says “The file format is not not recognized”, would you please be able to send me the originals for the first interactive box on this page. The one with the counter and the coin score board
Please Thankyou
woooohoooo these tourtorials or whatever are great and so is this bong
how exactly do u get the score to work because i cant get it to work.
I have done everything as the tutorial but i can’t set the score . Plz help me
I’m making a game where you move to the next level when you get a score of 10, and you move to the game over frame when you lose all of your lives. At the moment I have this:
if(_root.score = 10
gotoAndStop (5);
}
and:
if(_root.lives = 0
gotoAndStop (6);
}
but these codes just set my score and my lives to 10 and 0 respectively. How can I fix this?
Owen: You’re setting the score to 0, you need to use == rather than =.
== is equal to
= equals
Hey,
I’m trying to add a moving environment (precisely like the rotating line) into my game. However, the ball keeps hitting imaginary objects. All other environment objects from the last level were deleted. Instead of adding the “score” to the rotation speed, I just have:
onClipEvent (enterFrame) {
_rotation = _rotation+0.5;
}
Is there a fix for this?
scored 21 :D
hey Emanuele, great tutorial :)
i just have one issue though. I am trying to make a game, and i’m whenever i put more than 2 different hitTest’s in the actionscript of the hero, i get a bug.
Whenever i trigger one of the hitTest’s that i added as the last ones, my hero gets set to the point where it was supposed to, but then it dissappears right after.
What’s going on? :<
romario, please tell me excactly what you’ve done, and then i can help you :)
i dont know where to put the score = 0; in im new to this so plz explain
I’ve got a problem!
Ive made a game like this but When I have math random on my coin it goes onto one of the blocks in the enviroment making it impossible to get the coin! Please help!!!
Instances:
Player = “hero”
coin = “coin”
Blocks (all are in one movieclip) = “environment”
I have a problem. I’m making a game, and I want to have walls to make my hero retreat, not kill him. However, these “walls” could be curved, such as a river. The script doesn’t work properly:
onClipEvent (enterFrame) {
if (this._parent._parent.House2.hitTest(_x,_y,true)) {
speed*=-1 }
}
Could any one help me please? Thank you very much!
Thank you so much. Very neat tutorial! Easy to understand.
I have a question about how to make it go to a diffrent frame when the coin is reached. I am making a game so that when a coin is hit another moving obstacle appears. But when i add an actionscript like
if (_root.coin.hitTest(this.hero_hit)) {
gotoAndPlay(55); }
It does not collect the coin and i do not know why can some one please help me?
hi
nice tutorial.
i need help with the score. i have done the text named it and everything i put the code in the first frame. but when i run the game it just stays at 0 and does not move. i have flash 7 do you need to do something different.
Very nice tutorial. Got 14 woo hoo!
you need to have
_root.gotoAndPlay (number);
this is because it thinks the character’s frames when it just says gotoandplay.
ifyou say root.gotoandplay
it means the scene.,
if you say _root.wall.gotoandplay
it means goto the wall frame 2.
woot 20 but then its way too fast….
when the ball resets in my flash game the reset position keeps changing, for example if it touches the boundary it resets at _x 497 and _y 80 but when it collides with the wall a second time it resets further up and to the right of the original position. My version of Flash will not read the download version of the tutorials so I cannot view that and recitify the problem, can anyone help?
Can any one answer Amy’s and Peter’s questions?! I would like the answer too!
Also how do you set the rotation of the environment to the middle of the object? instead of the end
18 lolz :P
nice tut :)
Hello there, great tutorials indeed.
though I have a simple question. Because all this code is AS1.0 I m trying to write all the code in the frame 1 of the timeline instead inside my movieclip. as adobe supports it is better and I want to write AS2.0 instead. so I ve changed a bit the code (created the functions actually) like this :
stop();
var score:Number = 0;
var lives:Number = 2;
// b is the instance name of my hero.
b.onClipEvent(load) = function {
var power:Number = 0.3;
var xspeed:Number = 0;
var yspeed:Number = 0;
var friction:Number = 0.98;
var gravity:Number = 0.1;
var thrust:Number = 0.75;
var wind:Number = 0.09
}
b.onClipEvent(enterFrame) = function {
if (Key.isDown(Key.LEFT)) {
xspeed -= power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed += power;
}
if (Key.isDown(Key.UP)) {
yspeed -= power*thrust;
}
if (Key.isDown(Key.DOWN)) {
yspeed += power*thrust;
}
xspeed += wind;
xspeed *= friction;
yspeed += gravity;
_y += yspeed;
_x += xspeed;
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
_root.lives –;
}
if (_root.apple.hitTest(this.hero)){
_root.apple._x = Math.random()*320+30;
_root.score ++;
}
if (_root.lives == 0) {
_root.gotoAndStop(2);
}
}
but I get errors about line 5, 17. the erros are :
lines 5 & 17 : Expected a field name after ‘.’ operator.
typo :
I have:
b.onClipEvent(enterFrame) = function() {
…
…
…
b.onClipEvent(enterFrame) = function() {
there is a small bug in that game, if you hold down right and down, you go through the line…, not that it helps that much :p
and i got 13
33. if (_root.score <= 0){
34. _root.score = 0;}
35. else{
36. _root.score -=2;}
37. }
40. if(_root.score <= -1){
41. _root.score = 0;}
42. else{
43. _root.score ++;}
That will get rid of Negative scores, but very great tutorial:D, I just didn’t like the negative scores so I fixed it.
Change that first If to <= 1 because that’ll fix the wall negative error :D
ps 16 was highest score
i’m trying to make the movie skip to frame 2 when the player reaches the score 10.
i’ve tried:
if (_root.score==10) {
_root.gotoAndStop(2);
}
and this is not working for me. what can i be doing wrong.
how do u do a hittest and that when u hit it, it uses gotoandStop to goto the next level?
someone help because i’m confused
Umm, im not haveing scripting problems so mabey i have a gift for that (im 13) but how do i make an object, like water, transparent?
And i just managed to get 17 points!
how do you get the scoreboard thing up? this is my current code can someone please correct it?
onClipEvent (load) {
yspeed = 0;
xspeed = 0;
wind = 0.00;
power = 0.65;
gravity = 0.1;
upconstant = 0.75;
friction = 0.99;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xspeed = xspeed-power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed = xspeed+power;
}
if (Key.isDown(Key.UP)) {
yspeed = yspeed-power*upconstant;
}
if (Key.isDown(Key.DOWN)) {
yspeed = yspeed+power*upconstant;
}
xspeed = (xspeed+wind)*friction;
yspeed = yspeed+gravity;
_y = _y+yspeed;
_x = _x+xspeed;
_rotation = _rotation+xspeed;
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
_root.score -=2;
}
if (_root.coin.hitTest(this.hero_hit)) {
_root.coin._x = Math.random()*400+50;
_root.score +=1;
}
}
i know im going to look stupid for asking this because its going to be a simple answer but.
how do i make something that is not moving move?
i made it so your stuck and when you pull the lever i want the wall to move away then stop. and you can get thru…
Man this tutorial is great for newbs like me. I just want to know how you made the hero blend in with the water. It almost feels as if the hero is actually in the water.
Hey everyone… I kept trying to use that code on the character and put a ground so my character would be able to fly and also be able to land on the ground. The problem is that my character falls right through the floor… can anyone tell what to change in the actionscript or if there is an entirely different way to make your character fly and land?
Another question. How do u make the trigger go back to its original situation when the hero dies?
I have a question:
How do you make the coin not just appear on the same line in different places, but random places on the screen (except for the wall)?
Bumbanut, you notice that the coin is only moving along the x – axis:
_root.coin._x = Math.random()*400+50
“_root.coin._x” is the code in which it tells the coin to move in the x – axis.
The code “Math.random()*400+50″ is the area in which the coin is moving randomly.
All you have to do is make it so that it can move in a random direction along the y – axis too.
So the code will change the y – value of the coin.
_root.coin._y = Math.random()*250+50;
Make sure of how many pixels are the height of ur screen. I chose 250 pixels. This can vary in your stage.
Okay, Im quite a newb, and Im just trying to make a test game where its birds eye view and your a dot and you have to run away from other dots, through a maze. I have your code from the end of part 1, (thanx alot!), but I want it to turn you back, kinda like a bounce when you hit a wall, but just barely.
I have this code:
if (_root.wall1.hitTest(_x, _y, true)) {
yspeed = yspeed*-1;
}
if (_root.wall2.hitTest(_x, _y, true)) {
xspeed = xspeed*-1;
}
But (and this is the newbish part)
Where would I put that in relation to the rest of the code? Is it at the beginning or the end? Someone plz help me!!
very very good tutorial well done m8 well worth the effort you put in coz this was very helpful (written well) consider ego polished
happy new year all
Thanks to
“28. trys everything on January 28th, 2007 8:54 pm”
For helping me with the score box.
Im designing a video game currently… You are a dragon flying threw a massive dungeon. I made it so the lava pits work, but i cant get the score board functional, also i need some script on how to creat solid flooring,i whish to make him able to walk on land..
My current code
}
if (_root.gem.hitTest(this)) {
_root.gem._x = Math.random()*400+50;
_root.score ++;
}
}
All of the other tutorial has benn really swell so far, thnx it was really helpfull…
Wow i must sound like a winy nube, after all im only 13
Sincerely
Austin C.
PS plz any one feel free to answer if possible
Instead of
score = 0;
on the frame, do,
var score = 0;
Prolly the best tutorial ive ever read, ive seen tutorials that show u what to do, but this one is so much easier
Like Austin, I need to make a solid border/surface that is not deadly, so my ninja will not fall out of the playing area.
ATM I have removed gravity because it was making my friends go “WTF” But I need gravity for my ninja to “jump”.
Please feel free to email me.
Lemony Emily :)
Oh and btw Austin im only 12 ;P
Yeah, hey. Thanks a lot for helping me! This game I made is really cool with your help. I added some things and removed the ones I didn’t want, added new character, a main menu, and now it’s great! Thanks!
Dear, Emanuel feronato, Italian geek and PROgrammer, or any PROgramar who sees this and can help me out
I love your tutorial, and have been making horribly difficult levels for my friends to attempt to beat, they love it! Unfortunately, I have a problem! On one of my levels, I have three coins with instances coin, coin_2, and coin_3, all of which are programmed to teleport randomly when touched by the character and certain tweened killing environments. Unfortunately, they occasionally teleport outside the wall program, this is a huge dilemma, as it makes it nearly impossible to get any higher than 5 points!
I have a theoretical code that I think would probably solve the problem:
onClipEvent(enterFrame){
if (_root.coin.hitTest(outside stage)){
_root.coin._y = Math.random()*400+50;
}
but, it is full of errors, can you help me?
Also, can you make a tut for highscores? I want my friends to be able to compare highscores, and I didn’t see a section covering it when I skimmed ahead in the tutorial.
Thanks for reading!
Please post back!
-NEAR
Woopsie, me again, I found the answer to my own question, the
_root.coin._y = Math.random()*400+50;
is basically setting up the area where your coin can pop to, so I changed the code to
_root.coin._y = Math.random()*280+50;
on my coin actions and it worked like a charm.By decreasing the numbers I decreased the coin teleport area.
Also, expirement with X and Y coordinates if you want your coin to go all over the place!
Thanks for the free tuts emanuel
highest score = 1;
i prefer to program with classes its more organized
Highest score = 13
i plan to make a game using these tutorials! i’ll say thanks to you in the credits!