Flash game creation tutorial – part 4

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.

Welcome to the 4th step of this flash game creation tutorial.

Read steps 1, 2 and 3 if you're new to this tutorial, then follow this one.

The direction

Knowing the direction of the player may be very useful if we decide to add some special features to our game.
Always remember that it's useless to make a simple clone of a game. If you decide to inspire yourself to an existing game, add some new features, or people will ignore your work.

I'll explain you later in this tutorial how many pretty things you can do if you know the direction your player is moving.

Look at this actionscript

ACTIONSCRIPT:
  1. onClipEvent (load) {
  2.     yspeed = 0;
  3.     xspeed = 0;
  4.     wind = 0.00;
  5.     power = 0.65;
  6.     gravity = 0.1;
  7.     upconstant = 0.75;
  8.     friction = 0.99;
  9. }
  10. onClipEvent (enterFrame) {
  11.     if (Key.isDown(Key.LEFT)) {
  12.         xspeed = xspeed-power;
  13.     }
  14.     if (Key.isDown(Key.RIGHT)) {
  15.         xspeed = xspeed+power;
  16.     }
  17.     if (Key.isDown(Key.UP)) {
  18.         yspeed = yspeed-power*upconstant;
  19.     }
  20.     if (Key.isDown(Key.DOWN)) {
  21.         yspeed = yspeed+power*upconstant;
  22.     }
  23.     xspeed = (xspeed+wind)*friction;
  24.     yspeed = yspeed+gravity;
  25.     _y = _y+yspeed;
  26.     _x = _x+xspeed;
  27.     _rotation = _rotation+xspeed;
  28.     angle = Math.atan(yspeed/xspeed)/(Math.PI/180);
  29.     if (xspeed<0) {
  30.         angle += 180;
  31.     }
  32.     if (xspeed>=0 && yspeed<0) {
  33.         angle += 360;
  34.     }
  35.     this.hero_dir._rotation = angle-_rotation;
  36.     if (_root.wall.hitTest(_x, _y, true)) {
  37.         xspeed = 0;
  38.         yspeed = 0;
  39.         _x = 120;
  40.         _y = 120;
  41.     }
  42. }

the formula at line 28 allows us to know the angle (direction) the player is moving, starting from its x and y speed.
Of course, you have to know the bare bones of trigonometry, but it's very easy.
Lines 29-34 simply transofrm trigonometry angles into flash angles. This is due because of differences between flash axis system and trigonometry axis system.
Line 35 rotates a movieclip instanced as hero_dir of angles degrees minus the _rotation value, since the hero_dir movieclip is attached to the hero so it rotates with this one. So, if the hero has an rotation of 5 degrees and is moving in a direction of 85 degrees, the line of rotation should have a rotation angle of 85-5 = 80 degrees. Watch the movieclip to see how does it work.

Good. Now you can determine the direction your hero is moving in.
How can you use it?

One-direction walls

One-direction walls are walls that your player can pass through without crashing into them, for example, from left to right, while they still remain deadly if passed from right to left.

So I created a movieclip instanced as "oneway". Look at the actionscript:

ACTIONSCRIPT:
  1. onClipEvent (load) {
  2.     yspeed = 0;
  3.     xspeed = 0;
  4.     wind = 0.00;
  5.     power = 0.65;
  6.     gravity = 0.1;
  7.     upconstant = 0.75;
  8.     friction = 0.99;
  9. }
  10. onClipEvent (enterFrame) {
  11.     if (Key.isDown(Key.LEFT)) {
  12.         xspeed = xspeed-power;
  13.     }
  14.     if (Key.isDown(Key.RIGHT)) {
  15.         xspeed = xspeed+power;
  16.     }
  17.     if (Key.isDown(Key.UP)) {
  18.         yspeed = yspeed-power*upconstant;
  19.     }
  20.     if (Key.isDown(Key.DOWN)) {
  21.         yspeed = yspeed+power*upconstant;
  22.     }
  23.     xspeed = (xspeed+wind)*friction;
  24.     yspeed = yspeed+gravity;
  25.     _y = _y+yspeed;
  26.     _x = _x+xspeed;
  27.     _rotation = _rotation+xspeed;
  28.     angle = Math.atan(yspeed/xspeed)/(Math.PI/180);
  29.     if (xspeed<0) {
  30.         angle += 180;
  31.     }
  32.     if (xspeed>=0 && yspeed<0) {
  33.         angle += 360;
  34.     }
  35.     this.hero_dir._rotation = angle-_rotation;
  36.     if (_root.wall.hitTest(_x, _y, true)) {
  37.         xspeed = 0;
  38.         yspeed = 0;
  39.         _x = 120;
  40.         _y = 120;
  41.     }
  42.     if ((_root.oneway.hitTest(_x, _y, true)) and ((angle>90) and (angle<270))) {
  43.         xspeed = 0;
  44.         yspeed = 0;
  45.         _x = 120;
  46.         _y = 120;
  47.     }
  48. }

Line 42 Checks if the player hitted the oneway movieclip and if it has a direction angle from 90 to 270.
In this case, and only in this case, we know the hero is trying to pass the wall from right to left (remember that 0 degrees: right, 90 degrees: down, 180 degrees: left, 270 degrees, up), so the player dies.
The result of this actionscript is: if the wall can be passed from left to right, but it's deadly from right to left.

You may say: there's no need to play with trigonometry to do that: you can simply remember the old x position and verify that x position is increasing (moving to the right) or decreasing (moving to le left). That means I wasted a tutorial.

Or maybe not.

One-direction walls 2

Sometimes walls may not be just horizontal or vertical, and sometimes one-direction walls may allow to be passed only if the player has a given range of direction angle.

Now the oneway movieclip is rotated by 30° counter-clockwise

ACTIONSCRIPT:
  1. onClipEvent (load) {
  2.     yspeed = 0;
  3.     xspeed = 0;
  4.     wind = 0.00;
  5.     power = 0.65;
  6.     gravity = 0.1;
  7.     upconstant = 0.75;
  8.     friction = 0.99;
  9. }
  10. onClipEvent (enterFrame) {
  11.     if (Key.isDown(Key.LEFT)) {
  12.         xspeed = xspeed-power;
  13.     }
  14.     if (Key.isDown(Key.RIGHT)) {
  15.         xspeed = xspeed+power;
  16.     }
  17.     if (Key.isDown(Key.UP)) {
  18.         yspeed = yspeed-power*upconstant;
  19.     }
  20.     if (Key.isDown(Key.DOWN)) {
  21.         yspeed = yspeed+power*upconstant;
  22.     }
  23.     xspeed = (xspeed+wind)*friction;
  24.     yspeed = yspeed+gravity;
  25.     _y = _y+yspeed;
  26.     _x = _x+xspeed;
  27.     _rotation = _rotation+xspeed;
  28.     angle = Math.atan(yspeed/xspeed)/(Math.PI/180);
  29.     if (xspeed<0) {
  30.         angle += 180;
  31.     }
  32.     if (xspeed>=0 && yspeed<0) {
  33.         angle += 360;
  34.     }
  35.     this.hero_dir._rotation = angle-_rotation;
  36.     if (_root.wall.hitTest(_x, _y, true)) {
  37.         xspeed = 0;
  38.         yspeed = 0;
  39.         _x = 120;
  40.         _y = 120;
  41.     }
  42.    
  43.     if ((_root.oneway.hitTest(_x, _y, true)) and (angle<300)) {
  44.        
  45.         xspeed = 0;
  46.         yspeed = 0;
  47.         _x = 120;
  48.         _y = 120;
  49.     }
  50. }

Line 43 now kills the player if it touchs the walls in a direction that is less of 300 degrees (or: in a range from 300 and 360 degrees). This means you have to pass the wall paying a lot of attention to your direction: the range of angles allowed are only 30 clockwise and 30 counter-clockwise, so the direction of the player must be very similar to the direction of the wall.

This can only easily be done if you know the direction of the player.

Later in this tutorial you will find another amazing way to have a special feature knowing player direction.

Now it's time for player's speed.

The speed

Sometimes it's important to know the player speed.
Time to unveil the Pythagorean theorem:

In any right triangle, the area of the square whose side is the hypotenuse (the side of a right triangle opposite the right angle) is equal to the sum of areas of the squares whose sides are the two legs (i.e. the two sides other than the hypotenuse). (from Wikipedia)

Well, it's rather obvious that the hypotenuse is the absolute speed and the two other sides are xspeed and yspeed values.

ACTIONSCRIPT:
  1. onClipEvent (load) {
  2.     yspeed = 0;
  3.     xspeed = 0;
  4.     wind = 0.00;
  5.     power = 0.65;
  6.     gravity = 0.1;
  7.     upconstant = 0.75;
  8.     friction = 0.99;
  9. }
  10. onClipEvent (enterFrame) {
  11.     if (Key.isDown(Key.LEFT)) {
  12.         xspeed = xspeed-power;
  13.     }
  14.     if (Key.isDown(Key.RIGHT)) {
  15.         xspeed = xspeed+power;
  16.     }
  17.     if (Key.isDown(Key.UP)) {
  18.         yspeed = yspeed-power*upconstant;
  19.     }
  20.     if (Key.isDown(Key.DOWN)) {
  21.         yspeed = yspeed+power*upconstant;
  22.     }
  23.     xspeed = (xspeed+wind)*friction;
  24.     yspeed = yspeed+gravity;
  25.     _y = _y+yspeed;
  26.     _x = _x+xspeed;
  27.     speed = Math.sqrt((yspeed*yspeed)+(xspeed*xspeed));
  28.     _root.speed.text = "speed: "+speed;
  29.     _rotation = _rotation+xspeed;
  30.     angle = Math.atan(yspeed/xspeed)/(Math.PI/180);
  31.     if (xspeed<0) {
  32.         angle += 180;
  33.     }
  34.     if (xspeed>=0 && yspeed<0) {
  35.         angle += 360;
  36.     }
  37.     this.hero_dir._rotation = angle-_rotation;
  38.     if (_root.wall.hitTest(_x, _y, true)) {
  39.         xspeed = 0;
  40.         yspeed = 0;
  41.         _x = 120;
  42.         _y = 120;
  43.     }
  44. }

Line 27 applies the Pythagorean Theorem as explained above
Line 28 simply writes the speed in a text object.

How is the speed measured? It's measured in pixels/frame

How can we use the speed?

Speed walls

Sometimes you may decide to place a wall the player can pass through only if he has a speed greater than... something.
The new movieclip instanced as speed_wall is our new obstacle

ACTIONSCRIPT:
  1. onClipEvent (load) {
  2.     yspeed = 0;
  3.     xspeed = 0;
  4.     wind = 0.00;
  5.     power = 0.65;
  6.     gravity = 0.1;
  7.     upconstant = 0.75;
  8.     friction = 0.99;
  9. }
  10. onClipEvent (enterFrame) {
  11.     if (Key.isDown(Key.LEFT)) {
  12.         xspeed = xspeed-power;
  13.     }
  14.     if (Key.isDown(Key.RIGHT)) {
  15.         xspeed = xspeed+power;
  16.     }
  17.     if (Key.isDown(Key.UP)) {
  18.         yspeed = yspeed-power*upconstant;
  19.     }
  20.     if (Key.isDown(Key.DOWN)) {
  21.         yspeed = yspeed+power*upconstant;
  22.     }
  23.     xspeed = (xspeed+wind)*friction;
  24.     yspeed = yspeed+gravity;
  25.     _y = _y+yspeed;
  26.     _x = _x+xspeed;
  27.     speed = Math.sqrt((yspeed*yspeed)+(xspeed*xspeed));
  28.     _root.speed.text = "speed: "+speed;
  29.     _rotation = _rotation+xspeed;
  30.     angle = Math.atan(yspeed/xspeed)/(Math.PI/180);
  31.     if (xspeed<0) {
  32.         angle += 180;
  33.     }
  34.     if (xspeed>=0 && yspeed<0) {
  35.         angle += 360;
  36.     }
  37.     this.hero_dir._rotation = angle-_rotation;
  38.     if (_root.wall.hitTest(_x, _y, true)) {
  39.         xspeed = 0;
  40.         yspeed = 0;
  41.         _x = 120;
  42.         _y = 120;
  43.     }
  44.     if (_root.speed_wall.hitTest(_x, _y, true) and (speed<5)) {
  45.         xspeed = 0;
  46.         yspeed = 0;
  47.         _x = 120;
  48.         _y = 120;
  49.     }
  50. }

Line 44 makes the player die if he hits the wall with a speed slower than 5 pixels/frame.
Of course you can combine speed walls with one-way walls and normal walls... if you play well with those kind of walls you can create amazing mazes in minutes.

Time to introduce a new element now...

The dark

Since I hate the player (it's obvious, isn't it?) I want him to play in dark areas with only a spotlight around him.
The new movieclip I created is instanced as "dark" and consists in a big black rectangle with a hole in its center filled with a semi-transpared gradient.

ACTIONSCRIPT:
  1. onClipEvent (load) {
  2.     yspeed = 0;
  3.     xspeed = 0;
  4.     wind = 0.00;
  5.     power = 0.65;
  6.     gravity = 0.1;
  7.     upconstant = 0.75;
  8.     friction = 0.99;
  9. }
  10. onClipEvent (enterFrame) {
  11.     if (Key.isDown(Key.LEFT)) {
  12.         xspeed = xspeed-power;
  13.     }
  14.     if (Key.isDown(Key.RIGHT)) {
  15.         xspeed = xspeed+power;
  16.     }
  17.     if (Key.isDown(Key.UP)) {
  18.         yspeed = yspeed-power*upconstant;
  19.     }
  20.     if (Key.isDown(Key.DOWN)) {
  21.         yspeed = yspeed+power*upconstant;
  22.     }
  23.     xspeed = (xspeed+wind)*friction;
  24.     yspeed = yspeed+gravity;
  25.     _y = _y+yspeed;
  26.     _x = _x+xspeed;
  27.     _root.dark._x = _x;
  28.     _root.dark._y = _y;
  29.     _rotation = _rotation+xspeed;
  30.     angle = Math.atan(yspeed/xspeed)/(Math.PI/180);
  31.     if (xspeed<0) {
  32.         angle += 180;
  33.     }
  34.     if (xspeed>=0 && yspeed<0) {
  35.         angle += 360;
  36.     }
  37.     this.hero_dir._rotation = angle-_rotation;
  38.     if (_root.wall.hitTest(_x, _y, true)) {
  39.         xspeed = 0;
  40.         yspeed = 0;
  41.         _x = 36;
  42.         _y = 40;
  43.     }
  44.     if (_root.environment.hitTest(_x, _y, true)) {
  45.         xspeed = 0;
  46.         yspeed = 0;
  47.         _x = 36;
  48.         _y = 40;
  49.     }
  50. }

Then with only two lines (line 27 and line 28) we move the dark in the same way we move the player.
The result is simple but very amazing. The player has to move carefully through dark areas trying to spot walls before he hits them.

The last feature for this tutorial is a combination of dark and direction

The directional light

It works basically as the example covered before, but this time the dark movieclip does not have a spotlight but a directional light, so it will rotate in the angle the player moves. I told you knowing the player angle is useful...

ACTIONSCRIPT:
  1. onClipEvent (load) {
  2.     yspeed = 0;
  3.     xspeed = 0;
  4.     wind = 0.00;
  5.     power = 0.65;
  6.     gravity = 0.1;
  7.     upconstant = 0.75;
  8.     friction = 0.99;
  9. }
  10. onClipEvent (enterFrame) {
  11.     if (Key.isDown(Key.LEFT)) {
  12.         xspeed = xspeed-power;
  13.     }
  14.     if (Key.isDown(Key.RIGHT)) {
  15.         xspeed = xspeed+power;
  16.     }
  17.     if (Key.isDown(Key.UP)) {
  18.         yspeed = yspeed-power*upconstant;
  19.     }
  20.     if (Key.isDown(Key.DOWN)) {
  21.         yspeed = yspeed+power*upconstant;
  22.     }
  23.     xspeed = (xspeed+wind)*friction;
  24.     yspeed = yspeed+gravity;
  25.     _y = _y+yspeed;
  26.     _x = _x+xspeed;
  27.     _root.dark._x = _x;
  28.     _root.dark._y = _y;
  29.     _rotation = _rotation+xspeed;
  30.     angle = Math.atan(yspeed/xspeed)/(Math.PI/180);
  31.     if (xspeed<0) {
  32.         angle += 180;
  33.     }
  34.     if (xspeed>=0 && yspeed<0) {
  35.         angle += 360;
  36.     }
  37.     _root.dark._rotation = angle;
  38.     this.hero_dir._rotation = angle-_rotation;
  39.     if (_root.wall.hitTest(_x, _y, true)) {
  40.         xspeed = 0;
  41.         yspeed = 0;
  42.         _x = 36;
  43.         _y = 40;
  44.     }
  45.     if (_root.environment.hitTest(_x, _y, true)) {
  46.         xspeed = 0;
  47.         yspeed = 0;
  48.         _x = 36;
  49.         _y = 40;
  50.     }
  51. }

While lines 27 and 28 moves the dark movieclip according to player movements, line 37 provides the directional light rotation.

Well, that's enough at the moment. This tutorial is over but the game is way to be completed. You will learn how to manage lives, energy, enemies, room exits, code-cleaning and some other useful things.

Meanwhile, download the source of the examples covered in this tutorial and give me feedback.
At this time, you should be able to code a little game like Collectabubble or something more complex.
If you make a game following one mf my tutorials, or want to draw some graphics for walls or backgrounds for the final game, please give me your works and I will put them on this site with a credit to you and a link to your website, if any.

Continue to part 5

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (13 votes, average: 4.85 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.

55 Responses to “Flash game creation tutorial – part 4”

  1. anonymous on December 23rd, 2006 11:24 pm

    I would like to make it so that if your score reaches a certain amount you will go to a different frame

    does anyone know how?
    if so email me on will.h@hotmail.co.uk

  2. dunno on December 24th, 2006 4:02 pm

    ur tuorials are rubbish i followed the 1st one and thats it i did a bit of the second one but nne of it worked and this u dont even tell me how to do some the stuff u jsut say do this and that

  3. Emanuele Feronato on December 24th, 2006 4:12 pm

    If you download source codes you should make it work.

  4. nick on December 27th, 2006 3:54 am

    i realy like you tutorial but you still havent told us how to make the hero go to the next lev when you get the coin

  5. Matt on December 27th, 2006 7:33 pm

    Emanuele, I want to congratulate you on an excellent tutorial and also for not rising up to the rudeness of aome of the people who have posted comments here. Comments such as ‘Your tutorials are rubbish’ only show up these individuals as the childish and immature individuals that they truely are – it’s no wonder they can’t grasp even the simplest bits of actionscript when the first thing they do when they don’t understand something is throw the dummy out of the pram and cry like a baby ;) You’ve given up your own time and expertise for free and I personally think that so far it has all been incredibly simple and clear. Looking forward to the next part :)

  6. Alexander on December 28th, 2006 8:44 pm

    Hey!

    With help from your tutorial, I made a small game.
    Look at it yourself :)

    http://www.bottomatic.nl/spel.html

    It’s in Dutch, but I think you understand what to do :)

    Mail me if you like it :D

  7. lewis on December 30th, 2006 12:13 am

    that game is so cool but a bit easy

  8. Tony on December 31st, 2006 1:14 am

    Could someone tell me how to advance a level?

    I put this in the “Actions” layer but it doesn’t work

    if (score==10) {
    gotoAndStop(2);
    }
    else {
    gotoAndPlay(1);
    }

    The tutorial is very good, thank you Em.

  9. Emanuele Feronato on December 31st, 2006 5:51 am

    Advancing level is part of the next tutorial, to be released in a day or two.
    Stay tuned.

  10. bobby bean on January 1st, 2007 12:41 pm

    Hi
    I was learning flash and stumbled across your site. i found it really helpful and easy to fallow. it taught me a lot and showed me how to do a lot of things. thanks. i made a little game based on your tutorial.
    http://img128.imageshack.us/my.php?image=gameswl1.swf
    its nowhere near finished but our class is moving on to databases soon so I thing thats all it will get. If you want the source or how to do anything just email me at
    bobbybean@exemail.com.au
    once again thanks and bye :P
    P.S. big prize to anyone who can beat the LVL 5 big boss

  11. Darren Hunnam on January 1st, 2007 9:48 pm

    This is a fantastic tutorial and easy to follow, if people aren’t happy then by a freaking book about it.

  12. ricky on January 3rd, 2007 3:25 pm

    this thing is really gay

  13. Ashish on January 5th, 2007 5:59 pm

    A really helpful tutorial.

  14. dooey100 on January 27th, 2007 5:10 am

    Im having problems with the direction. I am using MX 2004, what are you using? The source files wouldn’t open , and what happens is that the rotation kinda jumps back and forth. Help please?
    (Otherwise a very nice tutorial)

  15. confused pinguine on January 30th, 2007 5:57 pm

    Very good tutorial as said.
    but I really dont get it with the darkness, if someone could help me I would be very thankfull

  16. sasa on January 31st, 2007 11:30 am

    verry good!!!!

  17. Mmmblah on February 1st, 2007 9:41 pm

    very very nice well done i tried it on flash and it worked perfectly I thank you for this wonderful tutorial.

  18. NoobInFlash on February 5th, 2007 2:27 am

    i dunno if u already explained this but how would i put in a guy different other than the square. wat i mean is how can i create wats stuff looks like iin the game. for example could i put a gaint lizard , if i made on, into the game. and aslo how would i create one in the first place. plz get bak to me.

  19. cole on February 22nd, 2007 5:09 am

    i want to know how to make the ball into something a bit more… you know complicated.
    can you tell me how?

  20. wah wah wah on February 27th, 2007 10:35 am

    the tutorials are great. Like someone already said, thanks for taking your time to do these. and for free too…you’re a great instructor. I hope the people that are complaining and saying rude stuff back up a step, relax, and keep trying. You’ll get it eventually and you will be happy you did. Quitting when it gets difficult and then blaming the guy who is giving a free tutorial is only going to get you into a bad habit that leads to a very unhappy life.

  21. a grateful user on April 12th, 2007 1:19 pm

    I just wanted to say that to put so much time into the tutorial is fantastic of you. The teaching is wonderful, every single step is explained in detail. I am surprised that so many people write to ask or comment on things that they need without first acknowledging the wonderful resource you have provided.

    I have no questions or complaints, I simply wanted to say thank you.

  22. Gilberto on April 15th, 2007 7:35 pm

    Hi Emanuele Feronato. Uhm, I have a problem with my game… You see, I’m making a game (in flash MX, it uses flash player 6.0) and I want it to look like a Crono Trigger… well my problem is that I want to include a lot of movie clips in the background and I’m using 2 kind of movement (in the center of the screen, the character changes its position x, y and when it hits the edge of the screen, then the background moves)… When I do so, the character and the bachground moves too slowly. I tried to change the vector images to GIF and PNG images but it’s just the same… I’d really appreciate if you answer to my mail dude. Well, thanks a lot. See you.

  23. leo on April 22nd, 2007 5:35 pm

    how would i make this into a drag race kind of game.
    i dont like it that theres walls and things

    sorry some spelings might be wrong in a hurry!

    email leoleo999@hotmail.co.uk if you want to help me

  24. Chance on July 8th, 2007 6:40 am

    Please tell me the program to put ACTIONSCRIPT in. Emanuele, please, if i cant make a flash game, i will lead a sad, deppressed life.

  25. some1 on July 20th, 2007 6:37 pm

    To use the action script in your flash software, right click on the simbol and click actions.

  26. some1 on July 20th, 2007 6:40 pm

    How come when i do that darkness tut the black parts top left corner sticks to my guy?

  27. anon on July 28th, 2007 7:18 pm

    I had the same problem as ’some1′, the dark symbol was moving with the hero but instead of the centre circle being over it, the top left corner is.

    I solved it by changing lines 27 and 28 to:

    _root.dark._x = _x – 780;
    _root.dark._y = _y – 700;

    Obviously the two numbers depend on the size of the symbol, but why have I had to do this?

  28. help on July 29th, 2007 10:28 pm

    I want the wall to reset the player opposite the way you have it on One-direction walls. Please help.

  29. Izzy on August 22nd, 2007 3:07 pm

    to anon:

    It is probably because the root of the symbol (marked by a sort of plus sign) is at the top-left corner of the lighter area… you can sort this by moving the lighening area so that the plus sign covers the centre of where your hero should be

    Hope this helps!

    Izzy

  30. Adam_ae on September 21st, 2007 12:27 pm

    Great guide, didn’t run into any problems with the tutorial other than a single missing “-” (my bad) which stumped me for quarter of an hour, preferred typing out the code rather than copy+paste, never goes well it seems.

    Thanks for putting up this tutorial, hopefully these tutorials will help me complete a decent game for once =P

  31. Connor on September 22nd, 2007 6:47 pm

    I’m pretty confused about the angle… I put in the same ActionScript as you, but the line doesn’t go to the left. Could you please help me?

  32. kippari on October 11th, 2007 8:35 am

    maybe you have not put the instance names there. or then youve put it in a wrong place

  33. Paul on October 16th, 2007 6:59 am

    I have used a control system where the left and right keys just rotate the character, and the up and down keys control its movement in the direction it’s pointing at.
    I’m in a bind now however, as I want to fire an object from the character’s weapon. Using the direction equation on this tut, my bullet just goes in the same direction, but it starts from the weapon like I wanted.
    How would I get the bullet to travel in the direction that the weapon is facing whenever I press the trigger key? I’m totally stumped.
    P.S. I think I’ve used more trigonometry trying to figure this out than ever.

  34. andy 60 on November 12th, 2007 12:09 am

    yer this is possibly meant for intermediates as you need to know how to create movie clips and things? i understand it and think it is fantastic however.

  35. Brian on December 25th, 2007 8:52 am

    this is real helpful. I’m serious!

  36. Umer on February 22nd, 2008 5:21 pm

    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 also i didn’t understand this one part 4

  37. trent on May 29th, 2008 3:29 am

    Hey, i’m really new to actionscript and game design, so here’s my question:

    I’m trying to make a platform game where the character can jump and fall down. In the first part I learned how to apply gravity, but when he falls, he goes of the screen! How do I make it so that when he falls he hits the ground and stays there?

  38. Samuel Benson on June 10th, 2008 3:38 pm

    For the direction of the circle I found that I had to alter the script of the ball because it did not 100% work, for all those out there who find that the line does not show direction for yspeed >0 and xspeed >0 heres what to do:

    if (xspeed=0 && yspeed0 && yspeed>0) {
    angle -=90;
    }
    this.hero_dir._rotation = angle-_rotation;

    I don’t know why but it does work :)

  39. Sant on June 27th, 2008 10:46 pm

    Your tutorials are awesome.They helped me understand the program flash 8. Thank a lot man.

  40. asfd on August 20th, 2008 8:30 am

    I don’t understand how you attach the hero_dir movie clip to the hero movie clip. Somebody please explain this to me?

  41. Matt 2 on August 20th, 2008 3:51 pm

    This is a great website, Emanuele, I am a total beginner but I found the site easy to use and very user friendly, thanks.
    But I still have a couple of questions:
    1. Whenever I create a boundary to stop my ball(the hero) I use the code:

    “if(_root.wall.hitTest(_x,_y,true)){
    xspeed=0;
    yspeed=0;
    } ”

    but this, for some reason, only slows down the ball, and it does not (as I had hoped for) stop the ball completely. I would like some assistance here.

    2. As I have NOT made my ball rotate according to the x and y movements, I want to make the ball face the direction it is travelling in instead. So I modified the above code to:

    “angle=Math.atan(yspeed/xspeed)/(Math.PI/180);
    if (xspeed=0 && yspeed<0) {
    angle += 360;
    } ”

    I am quite sure there is something wrong there as nothing changed in the animation. But, as I said, I’m just a newbie!

    Any help would be greatly welcomed, thanks!

  42. NuclearDuckie on September 11th, 2008 11:49 am

    Hey, do you know how I could make the character rotate to face the direction they’re moving in? I tried replacing the instance of the line with the instance of the hero, but that didn’t work…

  43. Teh Newby on September 27th, 2008 8:53 am

    Umm, yeah this is great and all, but where do you download the program? or don’t you use 1 at all? im really confused

  44. Teh Newby on September 27th, 2008 8:54 am

    email me with a reply kthx

  45. julian on October 11th, 2008 3:56 am

    hi,
    im having trouble with the
    one-way-wall.
    how do you make it that you can only go left?
    or up or down?

    -julian

  46. Alex Woodcroft on October 26th, 2008 10:17 am

    Can you please help me with the hero_dir line, I can’t get it to rotate at the center of the hero it goes everywhere.

  47. das on November 12th, 2008 11:52 pm

    sos un genio man!!!!!!!!

  48. NuclearDuckie on April 17th, 2009 9:19 am

    Teh Newby:

    The program is called Adobe Flash, formerly Macromedia Flash, and you can find it on http://www.adobe.com/

    Also, I figured out the problem I was having before. I forgot to remove “this.” from line 35.

  49. renato on May 9th, 2009 1:55 pm

    I was doing something here and my scenario and text follow the ball. How can I make them fixed to the stage?

Leave a Reply




Trackbacks

  1. Flash game creation tutorial - part 1 at Emanuele Feronato on December 23rd, 2006 6:29 pm

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

  2. Flash game creation tutorial - part 2 at Emanuele Feronato on December 23rd, 2006 6:30 pm

    [...] December 23rd update: 4th part released. December 6th update: 3rd part released. [...]

  3. Flash game creation tutorial - part 3 at Emanuele Feronato on December 23rd, 2006 6:31 pm

    [...] December 23rd update: 4th part released. [...]

  4. Flash game creation tutorial - part 5 at Emanuele Feronato on December 31st, 2006 11:25 pm

    [...] WordPress « Flash game creation tutorial – part 4 [...]

  5. Programming Tutorials / Game Making Check Video Description convert files from youtube : nocostlargish on November 9th, 2008 4:50 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/… [...]

  6. couponlargish » Vegas-Promotions.com on November 10th, 2008 1:32 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/… [...]

Posts