Flash game creation tutorial - part 2
Filed Under Flash •
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.
December 6th update: 3rd part released.
Welcome to the second step.
Read the 1st part and you'll be ready to follow me with the game creation.
As you can see, now I can move the hero in a quite funny way.
Now, it's time to introduce some (deadly) obstacles.
The bounds
Every game area has bounds, so I created a movieclip called "bounds" and instanced as "wall".
My hero can't touch any wall, so the actionscript will be:
-
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;
-
}
-
}
What happened?
I added lines 28 to 33, let's see how do they work.
Line 28: I perform a hit test between the hero and the movieclip called "wall". The _x and _y means that I am checking the collision only on the _x and _y attributes of the hero - its center -
Why am I doing it this way? Because I think the game would be too frustrating if I should check the collision between any pixel of the hero and the game bounds. Moreover, the smallest the collision area (1 pixel in this case), the more complicate and creative the bounds you can draw to make the player move around it.
Lines 29 to 32 simply "reset" hero's position in case of death.
The coin - 1st attempt
Now I want my hero to be able to collect coins or similar things, so I created a new movieclip named and instanced as "coin".
New actionscript is:
-
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;
-
}
-
if (_root.coin.hitTest(_x, _y, true)) {
-
_root.coin._x = Math.random()*400+50;
-
}
-
}
Look at lines 34-36.
Line 34 performs basically the same test as I did for the bounds, line 35 simply moves the coin to another position once you collect it.
Wonderful.
Now try to collect the coin.
It looks hard and buggy, isn't it?
That's why I am performing the hit test only with the center of the hero, I mean only with one pixel.
While this method was good for the bounds, now it looks awful.
The coin - 2nd attempt
I am trying a different approach, changing line 34 with
-
if (_root.coin.hitTest(this)) {
I am extendid the hit test to the entire shape.
Try to collect the coin now...
Now it's too easy!!
You can collect coins just staying close to them. Why?
Because Flash performs that hit test basing on a rectangular shape built around the hero's shape.
Just imagine a bounding box. Everything you hit with the bounding box returns a true value.
While the 1st attempt looked hard and buggy, this one looks easy and buggy. Keyword: buggy.
The coin - 3rd attempt
Are you about to give up? No?
Well, I have the solution.
Just create a new movieclip called "hero_hit" and insert into the hero's movieclip, at its center. That's the small blue square you notice on the movie.
Now perform the hit test on the hero_hit movieclip instead of the hero itself.
You can obvioulsy change the hero_hit size according to the feeling you want to give to your game.
The smaller the size, the hardes to collect coins.
Final actionscript is:
-
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;
-
}
-
if (_root.coin.hitTest(this.hero_hit)) {
-
_root.coin._x = Math.random()*400+50;
-
}
-
}
As you can see, the hit test at line 34 checks collision between the coin movieclip and the hero_hit movieclip
And here ends the second part..
Download the source code for all examples and experiment.
Of course, leave me feedback.
Continue with the 3rd step
Related Item: casino game
Tell me what do you think about this post. I'll write better and better entries.
They can be easily customized to meet the unique requirements of your project.
135 Responses to “Flash game creation tutorial - part 2”
Leave a Reply
Trackbacks
-
Flash game creation tutorial - part 1 at Emanuele Feronato on
November 18th, 2006 10:34 pm
[...] November 18th update: 2nd part released. [...]
-
Flash game creation tutorial - part 3 at Emanuele Feronato on
December 6th, 2006 1:57 pm
[...] Remember to read 1st and 2nd part if you are new to this tutorial, and let’s go. [...]
-
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
December 31st, 2006 11:25 pm
[...] Read steps 1,2,3 and 4 and you’re ready. [...]
-
A strange way to move the player with Flash at Emanuele Feronato on
May 30th, 2007 8:16 pm
[...] Lines 23-25: if the upper or lower part of the ball collides with the wall, I invert ball’s y speed because I am sure I touched the “ceiling” or the “floor”. For more information about hitTest method refer to this tutorial [...]
-
Rodrigo Flausino » Dicas de tutoriais e sites para criação de jogos em Flash on
August 30th, 2007 5:27 am
[...] Flash game creation tutorial - part 2 [...]
-
A Gem of Flash Game Tutorials | Newbie Game Programmers on
December 17th, 2007 4:22 pm
[...] game creation tutorial - Part 1 :: Part 2 :: Part 3 :: Part 4 :: Part 5 :: Part 5.1 :: Part 5.2 :: Part [...]

(8 votes, average: 4.88 out of 5)
HI
this is a very cool tutorial really.I liked it and i will make it.I am a beginner in flash so it is quite difficult for me.
But the tutorial is really cool.
another problem:
i pasted the code properly so that the ball can move, but instead of the ball simply going left and right while rotating the shape, the ball rotates round a point thats about 200 pixels away from it! i hope you understand that - it still moves left and right but swirls around and goes all out of control. Plus the gravity and speed don’t seem to be right because basically it’s very slow. by the way i am a beginner…
pleas just make it so
is key is down up he goes tn the direction he is faceing like a tank and make no gravity
really cool
But how would i edit the code so when it hits an object i want it to it goes to the next level (where i will put the next level)
We’ll cover it in the next tutorial, coming soon.
Wow. I read Part 1 and 2, and I really like this. I knew MOST of it, but for example, the square used to make the pathing better was a great idea that I would have never thought of. I never knew such a nice game like Ball Revamped could be made with such easy coding. Of course, this isn’t Ball Revamped yet. ;)
Also, I’m surprised that there are still people in the world that are so caring as you are. I’m glad there are people around that out of their free will, decide to help others that they don’t even need to help. If you were to not write these tutorials, it wouldn’t affect you in anyway, but instead it effects people you don’t even know.
But I have an issue. For some reason, even after I do all the things tutorials tell me to do, I can never get hitTests to work. Is there any way you can help me with it?
I have a movieclip titled hero, and the instance of hero, and this is the actionscript on it.
onClipEvent (load) {
power = 3;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= power;
}
if (Key.isDown(Key.RIGHT)) {
_x = power;
}
if (Key.isDown(Key.UP)) {
_y -= power;
}
if (Key.isDown(Key.DOWN)) {
_y = power;
}
if (ifthis.hitTest(_root.point)) {
_root.score = 1;;
}
}
Basically, as you can see, I want my dynamic text box with the instance of score to go up one point when my hero hits the point movie clip with the instance of point.
The movieclips touch, but NOTHING HAPPENS. Every time I try to to a hitTest, I get the same problem.
Your code:
if (ifthis.hitTest(_root.point)) {
_root.score = 1;;
}
Correct code:
if (this.hitTest(_root.point)) {
_root.score = 1;
}
I think
Ill try that.
Also, the two ;’s was a typo.
I think
if (this.hitTest(_root.point)) {
_root.score = 1;
}
Anyway scoring system and whatsoever is going to be explained soon.
Alright, it worked. Thanks a bunch.
how can i get the ball to bounce off the bounds instead of reset when it hits them?
Bouncing requires a close-to-real physics engine, that won’t be covered in this game creation.
Anyway, I am preparing some tuts on flash physics so come back soon.
By far one of the best tutorials in terms of making things clear to people and well written out. Can’t wait for 3 and beyond?
I have a question. I have a movie clip following my mouse, okay? And I have my actionscript set to where, when it hits another movie clip, my score goes up constantly. I’ve done a hittest that makes my score go up constantly before, but its not working this time. :( I always have problems with hittest actionscript. Do you think you could show me an example in coding that when you get a chance?
Awesome
your’e tutorial helped me allot
I have some problems. Even though I type the script the right way, the wall thingy won’t work. I have even tried to just copy it, and it still doesn’t work.
Can someone please help me??
hey man, ur tutorialz r greatt. i’m only 13 and i understand the script perfectly. ur a good teacher :P keep up the good work.
yeh, this is for No problemo, (yeah right!). same happened to meh, but its easier if u make a htin line ur boundy. just make a line fomrt he line tool…. select it, press F8, give it a name and then kepp the instance wall(or somehitng…this just an example). then on ur hero, type in this code:
if(_root.wall.hitTest(this)){
xspeed = 0;
yspeed = 0;
_y = 120;
_x = 120;
}
and voila, theres ur boundery. notice how i changes the:
(_x, _y, true)){
to :
(this)){
?
typing, (this)){ will make the entire line or shape the bondery instead of just one pixel of it.
p.s. thanks to this tutorial for giving me this info :P
I do it all right but when i move my guy the walls move with it wtf!?!
Personally, I never use more than one life on this if I understand this correclty. I just wonder why so many do not understand how this is. I guess that is the beauty of it all. Good post though!!
This is a great tutorial up to the point where you are supposed to create a wall. When I make my wall, I named it boundry. Ok, how do i use an instance or what ever you call it. When I drag the movie clip onto the screen, and play the game, it will not work… Why is this, care to share more details about the boundries? Thanks!
Ahh, I figured it out, you go to property’s and type in a name in . Now, though, I seem to be haveing a problem getting the blue square to work. How do you insert one movie clip into another? When I do it, the blue box remains still whereas the Hero does like normal. Why do they not move together? Thanks for any help.
They have to be in the same movieclip.
Download the source examples and you will figure out how.
This tutorial is awsome, the look and feel of the movement you get out of most tutorials is sad, but with your step by step explaination, it shows you just how each element affects your character, so you can choose the effects you want. you have the makings for greatness. but comment questions that are being left to you, offend me. as a learning programmer, I take pride in the work that I do. and I spend hours carfully reading books, and online tutorials. When people constantly send you questions that are obvious typos and simple careless mistakes like forgetting to assign instance names, it wastes time of people with real questions. Not to mention the time of the people reading the tutorial thinking they can learn more from the comments, when in fact they are reading usless bable… not unlike this… of course, I am making a point. not being an idiot. you rock. thanks for this tutorial
Rickey
web master, diamonddrake web design
i cant get the hero to pick up coins i instanced itand name it coin but it still doesnt please can someone help me
hey i cant make my walls work i added another layer and named it boundry and it still dosent work lol
Hey i have another question. When you make like wall boundries and coins do you paste you autoscript on to the coin for coin and wall for wall? or you continue doing the for the hero???
another thing how do you intense it?
hey nice tutorial ive done part one and 2 it works perfectly but is there a way to make multiple movie clips with the same instance name do the same thing? like instead of putting this:
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
i put that 4 times like this:
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
if (_root.wall2.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
if (_root.wall3.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
if (_root.wall4.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
is there a way to make the copies of a movie clip do the same thing without giving it a different instance name? cause i was doing my first ever game on flash and i made 150 enemies and only one worked so i had to frikin change the instance name of every one of them! lol can u help
omg my wall is still moving with the ball. How do i change that. plz tell me lol
Yoda check the actionscript is not on the wall as well. It doesnt need to be on the wall instance.
hey thanks Dan now its working all right
why is my ball goes right under the coin???
Do i have to make a new layer for the movie clip??
i am new to flash gmes and stuff but i dont get how to do the coin attempet 3 please help me
Hey the hero is working fine but the HitTest on the wall is not happening. My heroMC just goes under it! Also, when I download the source code it says invalid file format. Im using Flash MX 2004 - is that a compatability problem? Thanks, MAt
Hey, in coin attemp 3, I dont ubderstand the “insert hero_mc into the middle of the hero”. Can you please tell me in full details. And when I pasted your script in coin attempt three,the hero just move seperatly with the hero_hit.
i love you tutorial but is there a way so that you can put the coinb in a fixed place in stead of random?
When I tried the code, I had a slow frame rate and I noticed that the ball doesn’t rotate at the right speed, you can’t simply say
_rotation = xspeed; . This rotation glitch seems to be Conor’s problem as well. The ball is rotating at δ pixels/frame. The distance travelled is the length of the arc, which is r*α^c, where α is the angle subtended and ^c means its in radians. Since flash works in °, you must convert it to that. So, the distance travelled in 1 frame (δ) = 2πr*(α°/360), .: α° = 180*δ/πr, so, the rotation should be set to be equal to (180/πr)*xspeed. r is equal to half of the height of the hero, so, the final code for the rotation is:
_rotation = (180/3.14159*(0.5*_height))*xspeed; This fixed the glitch.
That’s amazing, I just wanted to make it rotate to simulate the speed, but you improved the whole thing a lot.
Thank you.
hello, umm.. i have a problem with the wall thing. every time i try it always goes under and passes through it like a ghost. please can you help?
Absolutely Bloody Brilliant!
The tutorial is really very cool.It is helping me to devlop different type of games too.
hey, so far this tutorial has been really good, but when i move my character at the wall really fast he goes straight through it, but when he goes slow it works.
Any one got any ideas?
oh yeah, and what if i want to make itn when my hero hits the wall it goes to a game over screen?
ok, i worked out wat was going on, if i’m holding down an arrow key while i’m heading at a wall my hero goes through it, but if i head at a wall and let go of the key b4 i hit the wall, my hero goes back to the starting point. But i still dont nkow y its doing it.
Great! I’ve never seen a tutorial like this. This tutorial is cool.
Thanks, Emanuele Feronato for publishing such thorough actionscript tutorials.
Can anybody explain why my code is broken? It is entered into the action window for PLAYER_MC. PLAYER_MC and GROUND_MC are both on layer1 frame 1. PLAYER_MC has some simple movement controls. When PLAYER_MC crosses GROUND_MC, this hitTest doesn’t work.
onClipEvent (enterFrame) {
if (_root.GROUND_MC.hitTest(this)) {
trace(”hitdetected”);
}
}
I have also tried writing it as
if (this.hitTest(_root.GROUND_MC)){
And I’ve tried it without “_root” No collisions are ever detected. Adding the following:
trace (_root.GROUND_MC.hitTest(this))
Returns nothing but “undefined”.
Thanks for any help, I’m learning flash and starting to understand and enjoy it, but this is really stumping me.
I really like your tutorial but I don’t like how you explain.
Example:
“Just create a new movieclip called “hero_hit” and insert into the hero’s movieclip,”
How do I insert it into the hero’s movieclip??
NM, figured it out. I didn’t give names to all of my instances.
sweet tutorial! im replacing the coin with rings, similar to a Sonic game, and its working. YAY! Hooray for tutorials
hey i’ve done up till the end of this tut. and my script is as below (the ‘hero’ is Sonic and the ‘coin’ is a ring and thw ‘wall’ are spikes, i’ve also taken rotation out.)
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;
if (_root.spikes.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
if (_root.ring.hitTest(this.sonic_hit)) {
_root.ring._x = Math.random()*400 50;
}
}
it works ok when i try it,but is there anything ive missed?
PS
No Problemo hve you given your movieclips an instance name each? and are they the same in the script?
ie, in my script above, i’ve given my ‘coin’ an instance name as ‘ring’ and replace the ‘coin’ in the script with ‘ring’
This tutorial is the best of the bestbut i was wandering why Whenever i add the rotation it always goes up before going sideways. why is that
Ryke,
double-click on the movieclip of your ball and you see that it brings you to an edit screen for that clip? Make sure the little crosshair is at the center of your ball. Once you do that you can double click anywhere on the frame and it should bring you back to your main screen. Test your movie out and let me know if that helps any.
Mike
Purple Chicken made a post in January that wasn’t answered by anyone. If anyone knows how please tell cus I have the same
Purple Chicken made a post in January that wasn’t answered by anyone. If anyone knows how please tell cus I have the same question. He said:
“hey nice tutorial ive done part one and 2 it works perfectly but is there a way to make multiple movie clips with the same instance name do the same thing? like instead of putting this:
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
i put that 4 times like this:
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
if (_root.wall2.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
if (_root.wall3.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
if (_root.wall4.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
_x = 120;
_y = 120;
}
is there a way to make the copies of a movie clip do the same thing without giving it a different instance name? cause i was doing my first ever game on flash and i made 150 enemies and only one worked so i had to frikin change the instance name of every one of them! lol can u help”
//any ideas anyone? It would be appreciated =)
//Thanks,
//Mike
Hi i need help!
I am making my spacship game but i need it to rotate on side to side movment and up down thrusts in direction its facing can anyone help?
Please e-mail me if you can
mcdonnell.13@gmail.com
cheers
Daniel,
Try doing this to rotate your ship.
if (Key.isDown(Key.LEFT)) {
_rotation -= 5;
}
if (Key.isDown(Key.RIGHT)) {
_rotation = 5;
}
I find 5 to be a nice speed to rotate at as it isn’t too fast or too slow. The up and down thrust movement you are asking about is mentioned in every one of these tutorials so I figure you know how to do that already.
stil a nice tutorial,
i got stuck with the collision because i rreally have no idee what movieclips and everything is but i now i have it almost perfect,
only my sprite inst perfectly round so it moves weird,
think i start on the next now
Zomg, damn good tutorial! Only one question… I created a movie clip called hero_hit, and instanced it as the same. But how do I get the hero_hit movie clip to move with the hero instead of just staying at one place and looking retarded.. please answer me anyone:D
I cant seem to get the wall to work. Well acually i dont get the wall at all. but i must say so far this is the best tutorial ive seen.
Oh never mind I got it now I forgot to read the part about making the movie clip and instance name. although i still cant get the ball to spin straight it always goes up and then down if i add the rotation,but only when i turn left or right, once rotation is off it stops
I don’t get the wall bit, I have added a movie clip surrounding the ball and named it wall but it still goes straight through! any ideas of what it might be?
P.S. great guide thx a lot!
Oh never mind, I just made the lines thicker and now it works!
guy i’m beginner i dont know how to do the bond plz help me …
help guy my e-mail is quockh2000@gmail.com send me how to do the wallplz
Hey! My hero dude is going way faster than yours in this tutorial. How can I slow it down?
I am creting a flash game and i was wondering if you could help me with the code for it. It is a maze where the cursor has to stay inside a line, when it reaches the end there is a button to press and it moves to the next scene. This tutorial was so helpful I thought I would ask about this.
When i enter the code, for the walls, the walls move around. this has happened twice now. weeblhater@yahoo.co.uk if you can help. thank you!!
i just started practicing flash yesterday i can make the ball move and turn (rotate) but it cant make it so the walls make it disappear (or die) i tried it even by starting over but… my ball just goes through the walls… anyone here to fix my mistake? this is the action code i put in
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;
}
}
……………………………………………………
an heres how the things were placed
key:
boundoury= …
ball= *
……………………………………..
. .
. .
. .
. * .
. *** .
. * .
. .
. .
. .
. .
……………………………………..
help would be greatly appreciated
sorry the map got cut off my mistake…
I was wondering how you put the hero_hit and the hero into 1 movieclip?
I couldnt open the source code files either. So Could someone PLEASE help me?
really good tutorial, helped me loads !! i have a crap understanding of actionscript but i still found this easy to follow.
cheers.
People asking about the hitArea part. Doubleclick on your ball movie clip and it will go into the movie clip where your ball is just a shape not a movie clip. In the movieclip create a new layer underneath or (above if you want to see it) your ball. In this layer create your hitArea square and convert it to a movie clip. Give it an instance name of hero_hit. Great tutorial.
i didnt get the bounds part, do i create a new symbol called bounds?
i did that and put it in different layer and pasted the code nd when i check it out the entire thing moves so if i press left the bounds(which i drew) move left with the ball inside?weird huh.
Uh ok, I really need help with my wall! I can get it to work sometimes, but its almost like if Im going fast enough it will just tress pass through it.
in reply to helpless:
this is happening because your bounds will be thin make them a very thick
AWSOME TUTORIAL!!!!!!!!!!!!!!!
and the comments were really helpful with the hero hit thingy. couldn’t have finished without it
THANKS!!
Great tutorial, love it! I had one problem with the walls, but thanks to abhilash’s comment, I was able to fix it.
I ahve a problem with the bounds. My hero just goes through the wall. Can you explain how to fix my problem?
Can u explain how to instance the bounds as “wall”?
i need help with hit checking. i want to get the wall to reset the ball as soon as it hits the edge not justhe center pixel but i can’t get it to work. i have tried using the thing done on the coin with the hero_hit but i can’t get that same method to work with the boundries.
hey guys, im new to flash games so this is a great tutorial, thanks!
Also, my wall moves with my hero, how do i stop that?
email me if you can help please!!!
aim_your_nukes@yahoo.com
how can it so that the hero_hit also works with the wall?
Really good tutorial. Thank you so much for taking the time to write it.
i need help so that when the ball hits the wall is will “gotoAndPlay” a movie clip
hi nice tutorial
i have some little problems
when i copy/paste the srcipt op gettingf the coin, it doesent work.
when i play the game, the hero juust pass under the coin.
it doesent dissapear but its imposible to me to get the coin please help me.
ps. i dont have a web page, just needed to write a flase one to write this
When i was trying to create the walls mine ended up very glitchy so i downloaded your source file. When i looked at your wall movie clip i noticed that the blue box that surrounds movie clips was in the center of the wall. How did you do this?
My friend told me about your tutorials and i love them. I was wondering if i could use some of your script to create an original game of mine. I’ll say I used your tutorials to help me make it.
Of course you can!
thanks
YOU LEGEND….!!!
Hi, I am making a retro game, and i dont want my delta to move in the way your hero did, so I skipped out the steps that made it all swurly, then I added the coins in without the code that makes it go swurly, but my charictar is not collecting the coins, just passing strait through them.
Hi
Excellent Tutorial.
I understand all of it aprt from the coin thing. In try to do it and when i do it says:
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 1: Clip events are permitted only for movie clip instances
onClipEvent (load) {
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 10: Clip events are permitted only for movie clip instances
onClipEvent (enterFrame) {
Please help
and also wat program do u use?
To lemony that is what happened to mine.
Try this code in your main charcter:
if(_root.coin.hitTest(_root.player)){
{ _root.coin._x = Math.random()*400+10; { _root.coin._y= Math.random()*400 + 10 } }
}
}
also make sure that the coin is an MC and hasnt got any coding in it!!
To David Azar i think u had the same problem as Lemony and posted the code that works with me above ^^^^
Thanks
Rhys
To flaming
to fix your wall problem what i did
was create 4 walls around my
lines (or wateva u call them!) and then put this code in each of them: Left = onClipEvent (enterFrame) {
if (this.hitTest(_root.player)) {
_root.player._x +=15;
}
}
Right = onClipEvent (enterFrame) {
if (this.hitTest(_root.player)) {
_root.player._x -=15;
}
}
Up = onClipEvent (enterFrame) {
if (this.hitTest(_root.player)) {
_root.player._y +=15;
}
}
Bottom = onClipEvent (enterFrame) {
if (this.hitTest(_root.player)) {
_root.player._x -=15;
}
}
View the tutorials or http://www.rasclerhys.com/Tutorials.php
Thanks!
again, easy to follow and really helped
keep up the good work ^_^
so i went to do this and wrote out all of the code and it comes with an error saying it needs to be a movie clip how do i make it one. could u put a link to show me this? im a bit new to flash
hi,
my hero walks always trough the walls, what kinda code i need that he should stand before???
so.. i too have this problem with the hitTest thing.
My character just passes through the wall no matter what i do :S
i named my character “hero”.
i named the wall “wall”.
i’ve tryed doing Rhys’s trick aswell, help :<
allright, i’ve figured it out (needed to instance the boundary >.< )
but my Flash is still awfully laggy, while the flash i see here works perfectly.
? :(
Okay,
“The bounds
Every game area has bounds, so I created a movieclip called “bounds” and instanced as “wall”.
My hero can’t touch any wall, so the actionscript will be:
PLAIN TEXT
ACTIONSCRIPT:
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;
}
}
”
That doesn’t work for me.. My player just goes through the walls.
What do I do if I don’t want to kill the character, but just stop them from leaving a defined area?
Try:
“if (_root.movieclip.hitTest(this)){”…
with “movieclip” as the name of the object that the movieclip you add this hitTest to will react to.
Hit test trange behaviour?
I created the walls as a movie clip and called the instance of the movie clip on my stage walls.
Now, the first if statement works the second doesn’t. The hero (red ball) doesn’t even more. Any idea why?
1) if (_root.walls.hitTest(this._x, this._y, true)) { ….
2) if (_root.walls.hitTest(_root.hero)) { ….
Hi Tommy
Silly question but have you named the instance of the wall on your stage in the property window?
HI.
First I want to say that the tutorial is very good, and that I have learned a lot of it. But it was really hard to understand some changes you made on the code from the first to the second part. Things that are the same but make confusing for some of us that are starting on this. like: On the first you used something like _y += yspeed; and then U change it to _y = _y + yspeed; now I know it is the same.
you would put the next level on a different level and you would have to make the object a button then make the action script:
on (rollover){
gotoAndPlay (2)}
EMPHASIS ON THE INSTANCE NAMING!!
(i forgot and wasted a lot of time trying to solve the problem DOH!!
hey this tutorial is so f-ing awesome omg.i really want to try it but… i dont know where to download flash. i want to make a cool game like this mmo called dofus it’s made with flash and it awesome but everything is for mem’s i want to make a game like that but no mem crap where it’s all like pay pay pay so tell me where to buy or download the flash game creation thing
Works fine until wall collisions they just wont work for me…
You just put a stop actionscript on the frame your at an then make a new frame and stop it. theres 2 levels
thanks really heplful!
can some one help i don’t know how to connect the hero movie clip with the hero_hit one.
This is sort of irritating me. =/
When I make a symbol and give it an instance name “wall” -I’m not confusing this with the symbols’ name- my program -Adobe Flash CS3- only considers the first “wall” symbol I made. All other symbols with the instance name “wall” are not accounted for and don’t carry on the appropriate actions regaurding the actionscript.
E.G. A black square -symbol name “thing”- and-instance name “wall”- at the bottom of my screen kills my guy appropriatley. But when I try to put more symbol “thing”s into the field and give them instance name of “wall” my guy passes through them. The bottom wall still works but the others dont.
Know what I’m doing wrong?
I worked around it by giving the walls action names of “wall1″, wall2″, wall3″, and “wall4″ and it works, but I have to write actionscript for all 4 walls. Not to mention is clogs my script box and makes it more difficult to find bugs, certain portions of action script that need rewritten, ect…
I have a problem. I added hero_hit to the hero movie clip, and I added the actionscript to the new-and-improved hero movie clip after I put hero_hit in (I went back to the “scene 1″ area, not inside the hero movie clip), and when I move over the coin movie in the test movie, the hero won’t “collect” the coin. I don’t really know what it is I should do.
reply to Connor:
make sure that hero_hit is an instance name.
wohoo thanks you are a hero!
How do i make him stand on the wall and not die
ok, i took the exact same code from your hitTest for the wall, and mine doesn’t work…….
I am trying to make it will not fall (which i made it do) but do not want to make a separate hitTest for each piece of wall.
onClipEvent (load) {
xspeed = 0;
yspeed = 0;
uppower = 7;
downpower = 5
friction = .75;
gravity = 5;
upconstant = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
yspeed -= uppower+upconstant;
}
if (Key.isDown(Key.DOWN)) {
yspeed += downpower;
}
if (Key.isDown(Key.LEFT)) {
xspeed -= uppower;
}
if (Key.isDown(Key.RIGHT)) {
xspeed += uppower;
}
_x += xspeed;
_y += yspeed;
xspeed *= friction;
yspeed *= friction;
yspeed += gravity;
if (_root.wall.hitTest(_x, _y, true)) {
yspeed = 0;
downpower = 0;
} else {
downpower = 5;
gravity = 5;
}
}
this is the part that doesn’t work
if (_root.wall.hitTest(_x, _y, true)) {
}
????????????????
I have used the exact same code as you did for the coin test, yet the hero does not collect it. Again, it is exactly the same apart from the graphics and yet it makes no difference. Some help on this matter would be appreciated? I tried the solution Rhys posted as well.
Hi JM if your still interested I may have been having the same problem, it wasnt going through the pot or left but was through the right and bottom?
It’s a lot more simple to make 4 lines, one one top,bottom, left and right, call them wall1/2/3/4 and in the
_root.wall1.hitTest(_x + _height/2, _y, true) {
}
that would be for the bottom wall if instanced as wall1.
Hope this is helpful for anyone having the same problem.
onClipEvent (load) {
doesn’t work for me it says there’s and error
any help? :)