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

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (50 votes, average: 4.70 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.
» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.

144 Responses

  1. [...] December 6th update: 3rd part released. November 18th update: 2nd part released. [...]

  2. Vasheeth says:

    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.

  3. Random says:

    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;
    }

  4. Random says:

    Umm… woops. Redo.
    if (_root.wall1.hitTest(_x, _y, true)) {
    yspeed = yspeed*-1;
    }
    if (_root.wall2.hitTest(_x, _y, true)) {
    xspeed = xspeed*-1;
    }

  5. Me says:

    Woho!
    I scored 21 :D

  6. Newbie says:

    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

  7. Newbie says:

    score done.
    :)

  8. Newbie2 says:

    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.

  9. teh nub nub says:

    great tutorial
    couldnt get past 17 on that last 1

  10. Tom says:

    WOOHOO I SCORED 800 MILLION

  11. eblup says:

    hey can you make one with a guy gravity ground water and boxes to hop acros.

  12. i best the game says:

    i beat ball revamped blblblblblblblblz

  13. sam says:

    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???

  14. jonimator says:

    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! :(

  15. [...] Read steps 1, 2 and 3 if you’re new to this tutorial, then follow this one. [...]

  16. diamonddrake says:

    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.

  17. diamonddrake says:

    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.

  18. Atilla says:

    Hi , how can i put the ”The killing tweened environment” , but also the ”Water” ?

  19. Andrew says:

    Nice tutorial :) hope there will be more of thees, how to make a “mario style” platform game maybe? ^^

  20. calle says:

    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!!!

  21. Fiz says:

    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

  22. Purple_Chikcen says:

    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

  23. Purple_Chikcen says:

    “gave put” is a typo woops i didnt put the word “put” in the script lol

  24. Purple_Chikcen says:

    wow been a while since hes replied to anyone

  25. Purple_Chikcen says:

    yus i scored 20

  26. Ryan says:

    I got 16 on my first try!

  27. Nabeel Quazi says:

    where exactly do i put the score variable thing? (the first actionscript on the page)

  28. Paul w says:

    i dont even get how to do the dynamic text box!?!? help!!!!!

  29. NeedHelp says:

    I am having torouble with the score please help me by telling me exactly what i have to do with the score

  30. trys everything says:

    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

  31. trys everything says:

    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?

  32. Mick says:

    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?

  33. confused pinguine says:

    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!!!

  34. K says:

    To Mick. Mark your textbox and check the properties. Right under where you choose color and size of the letters, the “var” box is.

  35. Arne says:

    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.

    ;)

  36. Trys Everything says:

    @confused pinguine

    wat you have to do is increase the frames per second (fps) to 50

  37. Mick says:

    yeah i checked there but on my flash theres no var box there…maybe i’ll just upgrade to flash 8 ;).

  38. George says:

    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

    =\

  39. helper monkey says:

    – 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

  40. im the best says:

    emanuele i mastered that spinning game i got 17!

  41. im the best says:

    Lol vasheeth you spelt beginner wrong

  42. im the best says:

    and mick flash 8, it rocks i suggest going for it

  43. [...] Read steps 1,2,3 and 4 and you’re ready. [...]

  44. [...] 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. [...]

  45. confused pinguine says:

    thx 4 ur help Helper monkey and trys everything!
    I appriciate it man…
    /\
    (or however u spell it…)

  46. Anonymous says:

    Great tutorial, bad for beginner because you don’t explain very much.

  47. Glucozade (Sonic fan #1) says:

    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

  48. -none- says:

    23 point!!!!!!!!
    beat that!!!

  49. Bubbler says:

    In response to diamond drake:

    your code:
    if (_root.lives==0) {
    gotoAndStop(2);
    }

    correct code:
    if (_root.lives==0) {
    _root.gotoAndStop(2);
    }

  50. Trevor says:

    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.

  51. Pit says:

    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!

  52. Pit says:

    oops, i meant instance! lol not variable

  53. Chris says:

    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?

  54. Jonny says:

    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?

  55. ru8ikscu8er says:

    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

  56. Chaos says:

    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?

  57. Smokey says:

    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;” ?

  58. shadowt says:

    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;” ?

  59. MasterZ87 says:

    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 ^_^.

  60. Aidin says:

    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?!

  61. Aidin says:

    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” ?

  62. dffdfdfdfdf says:

    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

  63. Liz says:

    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?

  64. Tom says:

    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

  65. Temporal says:

    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.

  66. Dragolux says:

    Man, I only got 14. :( Oh well. Great tutorial, EF!!

  67. Azz says:

    BOOYAH i got 16 points XD even took a screen shot =p

  68. peter says:

    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 :)

  69. pallmall says:

    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

  70. Teal says:

    Yay! I got a 31! I spent about an hour playing though… Anyways, great tutorial! I’m learning a lot.

  71. andy 60 says:

    yer me to sorry i’m probably missing something obvious its just the score i dont quite get :(

  72. Goinginsane says:

    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

  73. jitz says:

    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??

  74. spartan 117 says:

    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?????

  75. Mr. Flashie says:

    Cool. I love your site.

    Could you continue with your tutorial and help us making more interactive games, something like super-mario games?

  76. ive got a better idea, i can make custom lives but its more difficult that what you want…

  77. confused teenager says:

    newb question but i cant pick up my coin and i have triple checked the code and its the same… any suggestions

  78. Lemony says:

    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

  79. Flashtoo says:

    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.

  80. Flashtoo says:

    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.

  81. Flashtoo says:

    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.

  82. klap says:

    on the “water” example my charecter always seems to be “under water” or sunken, any help?

  83. Umer says:

    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

  84. Malik says:

    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

  85. bensta says:

    woooohoooo these tourtorials or whatever are great and so is this bong

  86. Bob says:

    how exactly do u get the score to work because i cant get it to work.

  87. romario says:

    I have done everything as the tutorial but i can’t set the score . Plz help me

  88. Owen says:

    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?

  89. Temporal says:

    Owen: You’re setting the score to 0, you need to use == rather than =.

    == is equal to

    = equals

  90. Keith says:

    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?

  91. The_erik says:

    scored 21 :D

  92. The_erik says:

    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? :<

  93. The_erik says:

    romario, please tell me excactly what you’ve done, and then i can help you :)

  94. newbie says:

    i dont know where to put the score = 0; in im new to this so plz explain

  95. Amy says:

    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”

  96. Jesse says:

    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!

  97. [...] Flash Actionscript Game Making Tutorialshttp://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/… [...]

  98. Coisox says:

    Thank you so much. Very neat tutorial! Easy to understand.

  99. [...] Flash Actionscript Game Making Tutorialshttp://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/… [...]

  100. hero says:

    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?

  101. Help me says:

    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.

  102. apocalypsefu says:

    Very nice tutorial. Got 14 woo hoo!

  103. 90301 says:

    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.

  104. woot says:

    woot 20 but then its way too fast….

  105. 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?

  106. 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

  107. bl00dsoul says:

    18 lolz :P

    nice tut :)

  108. newby geek says:

    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.

  109. newby geek says:

    typo :

    I have:

    b.onClipEvent(enterFrame) = function() {



    b.onClipEvent(enterFrame) = function() {

  110. bug says:

    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

  111. Jesse says:

    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.

  112. Jesse says:

    Change that first If to <= 1 because that’ll fix the wall negative error :D

  113. Jesse says:

    ps 16 was highest score

  114. tom says:

    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.

  115. flash noob says:

    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

  116. Zakk says:

    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?

  117. Zakk says:

    And i just managed to get 17 points!

  118. [...] Flash Actionscript Game Making Tutorialshttp://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/… [...]

  119. [...] Flash Actionscript Game Making Tutorialshttp://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/… [...]

  120. score newbie says:

    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;
    }
    }

  121. inotellmyname says:

    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…

  122. xZeRo says:

    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.

  123. [...] Flash Actionscript Game Making Tutorialshttp://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/…http://www.emanueleferonato.com/2006/… [...]

  124. platformergameobsessed says:

    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?

  125. xZeRo says:

    Another question. How do u make the trigger go back to its original situation when the hero dies?

  126. Bumbanut says:

    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)?

  127. xZeRo says:

    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.

  128. Anonymous says:

    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!!

  129. rob bob bobert says:

    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

  130. BenneyBoy says:

    Thanks to
    “28. trys everything on January 28th, 2007 8:54 pm”

    For helping me with the score box.

  131. austin was not on the computer says:

    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

  132. ANSWER to half your questions. i think. says:

    Instead of
    score = 0;
    on the frame, do,
    var score = 0;

  133. IFG says:

    Prolly the best tutorial ive ever read, ive seen tutorials that show u what to do, but this one is so much easier

  134. Lemony Emily killed a noob says:

    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

  135. [...] Just doing some playing around with flash and am working my way through the solid tutorial by Emanuele Feronato. [...]

  136. Bumbanut says:

    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!

  137. NEAR says:

    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

  138. NEAR says:

    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

  139. zard says:

    highest score = 1;
    i prefer to program with classes its more organized

  140. DannyDaNinja says:

    Highest score = 13

    i plan to make a game using these tutorials! i’ll say thanks to you in the credits!

  141. Helpmeplz says:

    I wanna make another level so when i get 20 points i ll go to the next level and i dont know qhy these actions here doesnt work

    if (score=20) {
    gotoAndStop(706);
    }

  142. Helpmeplz says:

    PS:and where put these actions

  143. Sam says:

    I am an absolute beginner and I’m wondering how do you even begin creating a game? Do I need any special software?

  144. [...] A year ago I messed around with Flash, not knowing anything about it and found a good tutorial that walked me through the basics. (The 3rd part of the series is here: Flash tutorial) [...]

Leave a Reply