Update: Part 2 released!
FrozenHaddock Tutorials: Simple Avoiding Game
In this tutorial you will learn how to create a simple dodge game, this will help learn about hittesting, whilst allowing new flash developers to get a quick and easy game.
You will be making a game like this;
The first thing we will do is set up our flash document. I’m setting mine up as 300×300px, 24fps and I’ve chosen grey as a background colour. You can choose different dimensions, but you will have to change the actionscript to reflect that.
Now we need to setup our character. Draw your character onstage and convert it to a movie clip (F8). Name it accordingly and make sure the registration point is in the centre. Then open up the properties bar for your player and set the instance name to player.

Now, open the character’s actions panel and give it these actions;
-
onClipEvent(enterFrame){
-
Mouse.hide();//hides the mouse
-
this._x=_root._xmouse;//sets the x of the player to the x of the mouse
-
this._y=_root._ymouse;//sets the y of the player to the y of the mouse
-
}
Now test your movie, the player mc will now follow the mouse, good. So lets move onto some enemies.
Draw your enemy on the stage, and convert this to a movie clip. As with the character name it accordingly and set the registration point to the centre.
Open up the actions panel for your enemy and add these actions;
-
onClipEvent (load) {
-
this._x = random(300);//sets the horizontal position randomly
-
this._y = random(-50);//sets the y position above the stage
-
speed = random(5)+1;//sets the speed randomly
-
}
-
onClipEvent (enterFrame) {
-
this._y += speed;//moves the enemy downwards
-
if (this.hitTest(_root.player)) {//if the enemy hits the player
-
_root.gotoAndStop(2);//goto the second frame, which will be a gameover screen
-
}
-
if (this._y>=310) {//if the player reaches 10 pixels below the stage
-
this._x = random(300);//randomly set the x, y and speed again.
-
this._y = random(-50);
-
speed = random(5)+1;
-
}
-
}
Test your movie now, and see your enemy fall down the stage. You can copy and paste this enemy for multiple enemies.
Now, before we setup a game over screen, we’ll setup a timer. (For a more indepth tutorial on creating this, see here)
Draw anything, and convert it to a movie clip. Move it off the stage.
Now, double click this to get inside the mc, and add a frame in at 24, or whatever value you set your fps at. open the actions of this frame and enter;
_root.clock+=1;
Double click anywhere to return to the main timeline, and click on your frame. Add these actions in;
-
stop();
-
clock=0
Right, so now the clock is timing, we need a way to see it. Use the text tool to add a new text box onstage. Open the properties bar for this text box, and change the drop down menu from ’static’ to ‘dynamic’
Then, keeping the bar open, change the var: input box to clock
Test your movie, you’ll see the clock time as you play.
Right, now for the game over screen, giving users their time and an option to replay.
Add a new blank keyframe on the main timeline. On this new frame setup the way you want it to look. Make sure to copy the dynamic textbox from the other frame wherever you want your players time to show. I have this;
(NOTE: I just realised, you’ll want to put Mouse.show(); on the frame here so you can actually click your button.)
Of course, we need to give our players the option to play the game again, so we need to setup a button. More information on setting up a button can be found on the site.
The actions we want on this button are these;
-
on(release){
-
gotoAndStop(1);
-
}
Now test your movie, and play your fully functioning avoision game!
If you learn more about hittests and variables, you will be able to setup scoring and powerups etc. But that’s for you to learn yourself!
Remember, post your creations on the Forum!
![[del.icio.us]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/digg.png)
![[Google]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/google.png)
![[StumbleUpon]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Windows Live]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/email.png)
June 19th, 2008 at 12:41 am
Hey! I made a game (using this tutorial) , but the ‘enemies’ don’t ‘kill’ the player. AKA, no game over screen. I used the exact code. Help? >>;;
June 19th, 2008 at 4:12 am
Make sure your instance names are correct, and capitalised the same in the code and in properties.
So make sure your player has the instance name of ‘player’ exactly, with no capital p.
That’s the most likely cause, if that doesn’t help email me the file and I’ll gladly take a look (Flash 8 pro or below, I don’t have CS3 yet)
You can email me at alternateaccount [at] frozenhaddock.co.uk
-Tom
June 19th, 2008 at 7:48 am
my timer wont work :S
June 19th, 2008 at 5:50 pm
What exactly is wrong with it?
Do you get any errors?
June 19th, 2008 at 8:23 pm
my 2nd frame timer wont work, i did the same thing as i did in frame 1.
also the button dont work well. i converted it to a button but it wont work :(
June 19th, 2008 at 10:25 pm
What about your second frame timer doesn’t work?
Make sure to check your variable names, and make sure they’re capitalised correctly, if you have any more trouble send me the file at the address above and I’ll have a looksee :)
June 19th, 2008 at 10:26 pm
Also, I’ve fixed the images, swf and fla links in the post.
Those might help :)
June 20th, 2008 at 2:02 pm
wow your great you even responded ( no1 normmaly does that)
the button works but on frame 2 the timer wont really work..all it say is 1.
even though i play in 10 seconds, it still says 1….any ideas? can make a tutorial?
( btw i tryed the same thing as the other timer on frame 1)
June 20th, 2008 at 2:03 pm
and i made a wall so the smileys cant go under the wall…can give me a code so the smileys get destroyed when they touch it? its a bottom wall.
June 20th, 2008 at 6:56 pm
I’m not sure what’s wrong with the timer, I’ll have a think :)
As for a wall, just swap out the current smiley code for this:
onClipEvent (load) {
this._x = random(300);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
onClipEvent (enterFrame) {
this._y += speed;//moves the enemy downwards
if (this.hitTest(_root.player)) {//if the enemy hits the player
_root.gotoAndStop(2);//goto the second frame, which will be a gameover screen
}
if (this._y>=310 || this.hitTest(_root.wall)) { /* if the player reaches 10px under the stage OR it hits a movie clip instanced as ‘wall’*/
this._x = random(300);//randomly set the x, y and speed again.
this._y = random(-50);
speed = random(5)+1;
}
}
Then just convert the wall to a movie clip, and make it’s instance name ‘wall’
Let me know how it works :)
June 21st, 2008 at 11:44 am
Thanks for all your help your just great :)
you know players can cheat in the game by let the player (mouse) off the game screen so they never get killed…any idea how to make them prevent it, like some walls that will prevent the player getting off screen?
The wall also works GREAT! thanks for it!
i cant make the timer work atm..
June 21st, 2008 at 11:50 am
the smileys are gone mad! i send you a email with my swf and you can chek it out (also the flash document)
June 22nd, 2008 at 11:31 pm
I’ll take a look tomorrow :)
As for stopping the player leaving the boundaries, I can do that whilst I fix your document :)
June 23rd, 2008 at 1:33 pm
Wow thanks for the help :)
your greeaaaaaat!
thanks
June 23rd, 2008 at 8:42 pm
There we go, sent you the fixed file, should all be ok :)
Your timer wasn’t working ’cause you had it setting it back to 0 on the second frame. You just needed to take clock=0; out of the actions for the second frame.
Your smileys went crazy, cause you had some inside each other. Instead of copying and converting to a movie clip (which leaves some inside others, and they go crazy) just hold control and drag one to duplicate it :)
To keep the player onscreen you just had to add this to the player:
if(this._x>=550){
this._x=550;
}
if(this._x< =0){
this._x=0;
}
if(this._y>=400){
this._y=400;
}
if(this._y<=0){
this._y=0;
}
Hope that helps!
June 24th, 2008 at 1:37 pm
Thanks…your so great :)
the first one that have ever helped me…ill add a credit page for you.. :)
Thanks for all your help..
June 24th, 2008 at 1:39 pm
I cant open the file :( im using flash mx….thanks anyway :)
June 24th, 2008 at 4:04 pm
Hello again!
What program you use for making fla files?
June 24th, 2008 at 4:58 pm
Flash MX?
Ack, I’m using 8 pro and I saved the file as low as I could (MX2004)
June 25th, 2008 at 2:40 pm
aww :( i cant open it :,(
I got mx 2004 it just says: unexpected file…
:( i googled it but so hard to understand.. .:(
thanks for all your help anyway…
June 25th, 2008 at 3:42 pm
Well, my advice is to delete your smilies and draw one again, covert it to a movie clip and copy and paste it a few times with actions on :)
Should make them work.
June 25th, 2008 at 3:45 pm
No, i cant open the fixed version….its not the thing with the smileys…
its the file you sent me it wont open…
all your work is wasted..sorry for wasting your time :(
thanks for all your help anyway.
June 25th, 2008 at 4:10 pm
I know you can’t open it, but that’s what I did to fix it :)
Try it and see if you can get your fla to work
June 26th, 2008 at 10:29 am
IT WORKS!!! THANKS!!! :DDDDDDDDD
I learned a LOT from this tutorial, so i want to thank you for making it…and helping me so much..
I learned how to make levels ( gotoandstop;1) something like that ( made a credit button and it worked!) you really helped me…..but looks like boundaries dosnt work that well, but its not necessary… :D thanks! But i have a request…..can you make me a script for a coin that pops up random and the player take them, then the points goes up….( a bar)
but thanks for All your help….your the best ever! :D
June 26th, 2008 at 10:33 am
^.^
I can indeed, perhaps Avoiding game pt.2?
Coins are pretty easy, boundaries I can explain properly too.
Anything else you’d like added in a second tutorial?
June 26th, 2008 at 12:00 pm
Levels…like when there are gone x seconds more enemys come when theres gone x seconds on wave 2 a new lvl again! :D
also some background music (different looping)
and when the game starts some time you die at the second, what if you could make a timer going down saying 3, 2, 1 GO then the enemys fall down…
also the smileys are only of the LEFT side of the game…never on the right side :( my window is 550×400.
also lifes, start like 3 lifes then when hit, the enemy stop comin and a life is gone ( a little heart) then the timer says again 3, 2, 1 Go then they come again.
ill think of more ask if you want more clear info :D
June 26th, 2008 at 2:52 pm
and a song button that does so the player can mute the sound :)
i keep find on more :D just tell me if its enough.
June 26th, 2008 at 4:04 pm
Sounds good!
I’ll get onto this, I think music’ll be a separate tutorial though!
June 26th, 2008 at 9:18 pm
Okay cool enough :)
also a menu button and pause button :D
June 26th, 2008 at 9:40 pm
http://www.kongregate.com/games/Ardavanski/smiley-avoider
heres my game :D
theres some bugs you can see you can just stick to the right never get hit and also if you hide at bottom you wont get hit..any ideas?
June 26th, 2008 at 11:27 pm
Change the numbers in the smiley code to fit your window:
onClipEvent (load) {
this._x = random(550);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
onClipEvent (enterFrame) {
this._y += speed;//moves the enemy downwards
if (this.hitTest(_root.player)) {//if the enemy hits the player
_root.gotoAndStop(2);//goto the second frame, which will be a gameover screen
}
if (this._y>=410) {//if the player reaches 10 pixels below the stage
this._x = random(5500);//randomly set the x, y and speed again.
this._y = random(-50);
speed = random(5)+1;
}
}
June 27th, 2008 at 2:03 pm
It works thanks :) could you give me a level code? like x seconds gone new lvl (frame) i know how to make the frames and stuff just not the script for x seconds…..and im sorry for asking for soooooooooooo much….. :(
June 27th, 2008 at 5:42 pm
No worries! You make me feel useful!
if(clock>=X){
_root.gotoAndStop(Y);
}
Where X is the number of seconds and Y is the level number/name :)
June 27th, 2008 at 9:40 pm
Cool, thanks :)
where you say Y isnt that frame?
And i look forward to see part 2 :D
thanks for all your help..you ARE useful!
June 27th, 2008 at 10:08 pm
And is it okay if i call you my partner/friend/actionscripter? mostly friend :P is that okay?
June 27th, 2008 at 10:21 pm
S’all good :)
(And yeah, frame number)
June 28th, 2008 at 4:07 pm
Thanks, your great!
June 28th, 2008 at 4:56 pm
The level code dont work, when i put it in frame 2, i put this in the frame if(clock>=20){
_root.gotoAndStop(3);
} but it dont the clock passes 20, but wont go to frame 3 wich is lvl 2
June 28th, 2008 at 5:00 pm
Also when the timer on frame 2 ( level 1), reaches 20 the level code( if (clock>=20){
_root.gotoAndStop(3);
})
makes it go to next level (frame 3) and the Timer WONT reset on lvl 2, it continues to 40 then it goes to lvl 3 and same….can you help me?
June 28th, 2008 at 5:09 pm
If you want it to reset just put:
clock=0;
On the 3rd frame :)
June 28th, 2008 at 5:10 pm
Thanks, but i didnt want it to reset it should continue as it was, + the code dosnt work :(
June 28th, 2008 at 11:42 pm
Ah, then make sure there is no clock=0; on the 3rd frame.
What code doesn’t work?
June 29th, 2008 at 11:25 am
the level code you gave me, wont work proper. I set it to make the clock reach 20 seconds, then it should move to lvl 2 (frame 3) but it wont….the clock continues from 20 and rises without go to frame 3 :(
June 29th, 2008 at 11:51 am
You need to put it inside an event handler :)
onEnterFrame=function(){
if(clock>=20){
gotoAndStop(3);
}
}
On the frame.
June 29th, 2008 at 12:48 pm
aaaaaaaaa thanks! your the best the best the beeeeeeeeeeeeeest in the whooole woooooooooorld!
June 29th, 2008 at 4:56 pm
Hooray!
June 29th, 2008 at 5:40 pm
Just tryed it and it works greaaat! just that when it reaches lvl 2, the timer wont continue from 20…just freeze there.. :( any idea?
June 29th, 2008 at 6:16 pm
Tazzydevil, while you are a sooooooooooooooooooooooooooooooooooooooooooooooooooooooooo good actionscripter and flasher why wont you make some more games? i have seen them at kongregate, and i liked them all, but i know that you can make something like the last stand…if you wanted to make a game, just tell me i could help you if you want! (somehow :D)
just think about making a game that will take more than 2 weeks development..im sure you could get some cash from mochiads, if it gets good…just think about it :) im always at your side.
June 29th, 2008 at 7:25 pm
I’ve got 2 small games awaiting music before they’re released, I’m not idle over here!
I’m also working on a cartoony style rocket game, I might post previews on the forum soonish :)
June 29th, 2008 at 7:26 pm
For the timer on level 2, you need to make sure you have the timing movieclip still in place on the frame :)
June 30th, 2008 at 1:21 pm
Cool, cant wait to try your games! :D
& now the clock works but it goes 2 seconds up per sec…like this 1 real second is 2 in the game :O
June 30th, 2008 at 1:25 pm
It works now thanks :)
June 30th, 2008 at 2:13 pm
Hello again, i just made a new mode named Survival where you must survive as long as you can nonstop ( the other mode is normal play with levels :D)
but the timer in survival mode wont work, all it say is NAN. The level frames are from 2 to 6. the survival mode frame is on one single frame; 11. everything else works in frame 11 just that the clock dont work ( i got the anything drawn thing there, the clock dynamic box, EVERYTHING just still says NaN. Can help me?
June 30th, 2008 at 4:17 pm
On the frame for survival mode, make sure that the line:
clock=0;
Is there. NaN is displayed in a box when the variable is altered but it hadn’t been set already :)
June 30th, 2008 at 5:20 pm
thanks! :D if theres a KING of flash…its you….
your greaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat the best best best in the whooole wooorld!
June 30th, 2008 at 5:21 pm
Can you help me make a highscore stat for my game in kongregate? i have the root_connect.kongergate thing but i dont understand how to make a MAX thing on there..its for max time survived
July 1st, 2008 at 6:25 pm
everything works well except when i put the mouse over the button, it doesnt give me a chance to click it cos the text that says “Retry” gets in the way! help!
July 1st, 2008 at 9:44 pm
Ardavan: I’ll look up the Kong API later, tired at the moment :P
Dannil: Wha? The retry text should be part of the button.
July 2nd, 2008 at 7:29 pm
Hey. I’m trying to make a screen at the front so I can click play now instead of going straight into the game. Any idea on how to do this? Also, with the replay button, I add the mouseshow but it doesn’t work it just says theres a script error. Any Help?
Thanks
July 2nd, 2008 at 7:39 pm
To make a frame at the start, just highlight all your current frames and drag them across one frame. That should create a blank frame. Then put stop(); on this frame.
Then create a button on this frame with-
on(release){
gotoAndStop(2);
}
You’ll need to change the frame numbers on the smilies to the gameover screen (which will now be frame 3) and the replay button to frame 2.
As for Mouse.show(); have you got it on the button? It should be on the frame :)
July 3rd, 2008 at 9:48 am
I understand that :)
you done so much for me :D
i wont ask you for questions for a long time:)
July 3rd, 2008 at 10:01 am
OKay last question; when the player complete my game, he go to a frame with congratulations you beat smiley avoider! then theres a menu button. when the player clicks that, he see 1 second on the menu and then it goes to the winner frame again! so he need to restart the page to play the game again can you help me?
July 3rd, 2008 at 3:41 pm
Are you determining your win by the clock variable?
If so, just put:
on(release){
_root.clock=0;
_root.gotoAndStop(MENUFRAME);
}
And I don’t mind the questions, just I don’t know Kong’s API too well ;)
July 5th, 2008 at 5:35 pm
thanks :)
July 7th, 2008 at 12:06 am
When I enter the code to make your character move (charsetup), it gives an error. It says the error is located in the first line.
“1087: Syntax error: extra characters found after end of program.”
If you want, I can send you a screenshot.
Thanks
July 7th, 2008 at 1:28 am
Hmm… I’ve never had that error before…
Are you sure you’re using the correct version of ActionScript?
July 7th, 2008 at 1:34 am
how do you make the enemies move right or left insdead of down?
ps hey ardavan i love your game add walls to it!
July 7th, 2008 at 1:37 am
euhm, AS3.0 in Adobe Flash CS3
thanks for quick response
July 7th, 2008 at 3:16 am
Aha, there’s your problem!
You need to be using AS2 :) CS3 can handle that too, just change the settings under publishing.
July 7th, 2008 at 3:20 am
@Mushyrulez:
You’ll have to change the code on the enemies. Instead of increasing Y, decrease X.
Also, you’ll have to change the original positioning of them.
Tell me if you need more help with this and I’ll write something tomorrow.
July 7th, 2008 at 9:13 am
ok thanks
July 7th, 2008 at 10:10 am
the hittest won’t work my enemy just goes through it
July 7th, 2008 at 5:21 pm
thanks Mushyrulez
good to hear that you like it :)
how walls?
July 8th, 2008 at 7:00 pm
I’ve found something easy for walls without using a wall movieclip.
I don’t think someone already said this, if someone already said this sorry.
Replace the old code of the player (cursor) by this:
onClipEvent(enterFrame){
Mouse.hide();
this._x=_root._xmouse;//sets the x of the player to the x of the mouse
this._y=_root._ymouse;//sets the y of the player to the y of the mouse
if (this._y>=300) { //if the cursor moves to 300, it will automatically move to 300 (so you can’t go further than 300)
this._y = 300;
}
if (this._y=300) {//same here
this._x = 300;
}
if (this._x<=0) {//same here
this._x = 0;
}
}
July 8th, 2008 at 7:19 pm
oh sorry, you already said it :$ sorry
July 8th, 2008 at 11:14 pm
@Toomin
Make sure you check the instance names on your player and in your enemies actions.
They should match exactly, including capitalisation.
@Giel
No worries! :)
July 9th, 2008 at 5:35 am
how do you input lives in it? i think 1 life is too hard…
July 9th, 2008 at 1:34 pm
To add lives, you’d just create a variable on the frame for lives:
lives=3;
Then on the enemies:
onClipEvent (load) {
this._x = random(300);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
onClipEvent (enterFrame) {
this._y += speed;//moves the enemy downwards
if (this.hitTest(_root.player)) {//if the enemy hits the player
if(_root.lives< =0){
gotoAndStop(GAMEOVERFRAME);
} else{
lives-=1;
this._x = random(300);//randomly set the x, y and speed again.
this._y = random(-50);
speed = random(5)+1;
}
}
if (this._y>=310){
this._x = random(300);//randomly set the x, y and speed again.
this._y = random(-50);
speed = random(5)+1;
}
}
That should do the trick :)
July 9th, 2008 at 5:00 pm
thanks! i tried doing walls so that the player and the enemy can’t pass through them, and it doesn’t seem to work… do you know the problem?
July 9th, 2008 at 5:10 pm
oh yeah the lives thing doesn’t really work… everytime the enemy hits me the enemy just restarts, so you’re kindof invincible….
i have another question if you want to make different setttings for each “level” do we have to make a new frame?
July 9th, 2008 at 11:15 pm
It should take the life off before resetting…. Not really sure what the problem is.
Perhaps you need _root.lives-=1; (I was in a hurry earlier :S)
If you were duplicating enemies with AS rather than by hand you could set a variable for how many and do it in one frame, but with this method you’ll need to make new frames :)
July 10th, 2008 at 3:13 am
you can make the enemies move from the right side to the left side of the screen, and other directions like that right? but is it possible to make them be diagonal =D?
July 10th, 2008 at 12:05 pm
No reason why not!
You’d just add/subtract the speed to both X -and- Y, but placing them originally and resetting them would need thinking out more :)
July 10th, 2008 at 8:53 pm
hey can you check my fla file? i sent it to alternateaccount@frozenhaddock.co.uk under dontask@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com
thanks! can you check what’s wrong with the walls and the enemies? thanks again!
July 11th, 2008 at 6:36 pm
I’m stuck on the timer part. You said “Now, double click this to get inside the mc, and add a frame in at 24, or whatever value you set your fps at. open the actions of this frame and enter”
But it doesn’t give me a window to change the frame rate or anything :S
Please help
July 12th, 2008 at 12:44 am
@Mushyrulez
I can do now, yesterday was a little dodgy for me, the SQL server died for a bit, as did my home network. Apologies for the delay :)
@lololol
Your frame rate is set at 12fps by default, so unless you’d changed this by clicked settings on the properties bar earlier, you’d put a frame in at 12 on the new timeline that should appear after double clicking the timer movie clip.
July 12th, 2008 at 2:23 am
hey i just made mine and it completely does not work (i cant move the character, enemies dont attack, timer doesn’t work)is there something wrong with the coding that i put in or something?
July 12th, 2008 at 2:31 am
There’re a few things everyone should check if things aren’t working :)
– Are you using AS3 instead of 2? This tutorial is for ActionScirpt 2, and if you’re using Flash CS3, it’ll be set to AS3 as default…. so check that.
– Instance names, need to be exactly the same in the actions as they are on the movie clip, this includes capitalisation and missplaced spaces, so double check those too!
– Is the coding in the right place? This tutorial has actions in several places, are the right pieces in the right place?
If that doesn’t help, try sending me your fla file (In Flash 8 or below format please) and I’ll take a look :)
July 12th, 2008 at 5:46 am
I made a game with your tutorial xD
http://maitealatte.deviantart.com/art/Flash-game-D-91421235
July 12th, 2008 at 8:44 am
Hello! You need the game over screen, because the enemies wont ‘kill’ ye if ye don’t make it.
July 12th, 2008 at 1:51 pm
Please Help Mine Wont Time And Cant Make Link :(
July 12th, 2008 at 3:29 pm
I’m stuck adding the actions for the player I test it and it does nothing. I have Flash MX 2004..
July 12th, 2008 at 10:21 pm
Hey, I am making the Game with the tuturiol and I am confused with the timer, I did what your tutriol said only on the frame that the outside object is on, and didnt put any script on the main icon and the main game page, the timer doesn’t work though? can you help!
July 12th, 2008 at 11:25 pm
@Mai
Looking nice! Thanks for sharing :)
@Josh
Hmm, the timer seems to be a problem for a few people, I’ll make sure to show you guys a better way with part 2 of this tutorial coming soon. For now, what exactly is wrong with it? Do you get any errors? Remember to double-check your variables and your actions inside the timer need a _root. before the variable name!
@Tom
Are you definitely adding the actions in the right place? The player should be a movie clip, and the actions should be on that. Have a look over it and run through the tutorial again, and if that doesn’t work, email me your .fla (My address is on the contact me page) and I’ll have a look and see what I can do :)
@gamer103
I’m not quite sure I understand your problem, but I’m just now going to write a more indepth tutorial on making the timer itself, make sure to take a look and comment again if you’re still having trouble ;)
Wow, lots of comments today! Welcome to all the new readers!
July 12th, 2008 at 11:38 pm
@Mushyrulez
You’re using CS3, and it’s exported as such. I only have Flash 8 Pro, could you save it as a Flash 8 document and send it to me again? I can take a look then :)
July 13th, 2008 at 12:19 am
[...] to create a timing system in Flash, and this is the way with less Actionscript that was used in the Create a Simple Avoiding Game tutorial, but several people have commented that they had trouble with it, so here’s a more in-depth [...]
July 13th, 2008 at 4:15 pm
I Have Sent You My File Please Can You Make The Timer Work And And Walls Please Thanks
July 13th, 2008 at 5:24 pm
I shall do later when I have some more time, for now I suggest you take a look at the new tutorial on making this timer, it might help you out :)
http://frozenhaddock.co.uk/2008/07/making-a-simple-timer-in-flash/
July 13th, 2008 at 8:26 pm
hi! First thanks for the tutorial, and second, I am confused about the timer, how to add it that is, I opened up the object that goes offstage and added a frame, on that frame I put on the root clock+1 thing, then on the regular main frames script I wrote stop(); clock=0, can you tell me why this doesn’t work please!
July 13th, 2008 at 9:28 pm
I’m not sure.. it should work from what you say.
If you email me the file (Flash 8 or before please) I can take a look for you, if you want?
:)
July 13th, 2008 at 9:32 pm
Okay so!
I have everything done, but the timer is going wild.
Like it goes fast, and then stops D:
im not sure why it’s doing this.. any tips?
July 14th, 2008 at 2:14 am
Hmmm, I’m not sure what the problem might be. Did you try looking at the more detailed tutorial on it?
If it’s still freaking out, you could email me the file (Flash 8 or below) and I’ll take a look :)
July 14th, 2008 at 6:51 am
OK I am having these problems…
Enemy’s won’t “kill” the player. (Code and properties match)
Couldn’t get the timer to work so i deleted it for now.
Also, I keep getting this error, “Statement must appear within on/onClipEvent handler
Mouse.show()”
It’s on my second frame.
July 14th, 2008 at 7:21 am
Hmm, first of all, are you using AS2? Some people are using CS3 and it defaults to AS3… which is a problem.
There’s a more indepth tutorial on the timer on the frontpage currently, if you want to take a look. I’ll be showing another method of timing in a soon-to-arrive tutorial.
If your problems persist with Mouse.show(); Then replace it with:
onEnterFrame = function(){
Mouse.show();
}
That should fix it. If that doesn’t help, email me your file and I’ll take a look :)
July 15th, 2008 at 5:59 am
I am using Macromedia Flash Pro 8. I JUUUUST started getting into flash so I am not sure what AS2 and CS3 are…
I learn things very quickly so once I learn a few tricks I should be rolling right along.
July 15th, 2008 at 8:30 am
okok. If you meant Action Script 2 then on the drop down menu it says Action Script 1.0 and 2.0. So I am assuming I am using it….
July 15th, 2008 at 8:49 am
Sorry for all the comments, I just keep experimenting with it.
I deleted the 2nd frame and it works fine, minus the enemies not killing the player. So I started the whole 2nd keyframe from scratch (except the clock). I inserted it right next to frame one and set up the game over screen. Now when I test the movie it flashes back and forth really fast and never stops…..hmmmmm.
July 15th, 2008 at 10:05 am
bah, I wish I could delete my other comments….
So I remade it….it works…sorta…although I have new problems.
If I copy and paste the enemy, only the original enemy can kill the player. Both enemies have the same AS and instance name. Also, the enemy won’t go to the bottom of the screen. I changed the AS to
this._x = random(400) because that is the height of my document…
Lastly, I can’t get the retry button to work now on the game over screen.
July 15th, 2008 at 12:42 pm
Hi!
Thanks for a GREAT tutorial! =)
I’m trying to do following:
When the enemy hits the player I want the enemy to go UP instead of down…
I’ve tried to do it like this:
onClipEvent (load) {
this._x = random(300);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
onClipEvent (enterFrame) {
this._y += speed;//moves the enemy downwards
if (this.hitTest(_root.player)) {//if the enemy hits the player
if(_root.lives=310){
this._x = random(300);//randomly set the x, y and speed again.
this._y = random(-50);
speed = random(5)+1;
}
}
That works… but not perfect =) I guess you can understand why…… It goes UP on hit, but after that I can hit it again, and again… I want the enemy to be “disabled” when I hit it…
Hope you understand =)
July 15th, 2008 at 1:27 pm
=) I have another question:
I know that the following line of code tell the game where to put the enemey horisontally:
this._x = random(300);//sets the horizontal position randomly
The game area is 300px wide… and if I change it to random(150) it will only put enemies on the left side of the game… but how do I change it to only put enemies on the RIGHT side of the game?
I want different enemies on every side =)
July 15th, 2008 at 9:22 pm
@Aaron
The enemy itself shouldn’t have an instance name, the player should. If you remove instance names from the enemies they should work.
You need to have a semi-colon on the end of that line of AS.
Aaand, what about the button doesn’t work? Have you checked the frame labels?
July 15th, 2008 at 9:31 pm
@Oskar
Thanks! I’ll see what I can do to help…
I’m not sure I understand what you want for the first part, You mean hit the player and -immediately- start going up? Or spawn below the stage and move upwards then?
As for problem two, that I can help with ;)
this._x=random(150)+150; will make them appear on the right only.
random(150) will return any value between 0 and 150, then +150 will make the range 150 to 300. :)
July 15th, 2008 at 10:15 pm
I finally got it to work. I thought the enemy had to have an instance name for some reason. Got rid of that and it worked fine. (Had to edit my enemy a little since everything works in boxs, because you could die without actually touching the enemy.
As for the button, I had the text set to Dynamic still. So I changed it to Static and it worked fine.
Now I am going to attempt a start screen. I’ll post it when I finish it. Thanks for this tutorial….I have learned so much! XD
July 15th, 2008 at 10:56 pm
Can’t seem to get it to work… here’s what it looks like…
Frame One - Title screen with “play button” with these actions
on(release){
gotoAndStop(2);
}
Frame Two - Actual Game with timer
Frame Three - Game over with timer
It just skips to frame two when I test it and the enemies won’t kill the player.
July 15th, 2008 at 10:59 pm
Make sure you have stop(); on frame 1.
Aaand, that button should work…
Did you name the frames?
July 16th, 2008 at 1:19 am
Yeah, I read through the comments, (which have been helpful in their own respect), and figured that out. I now have a full working game with 8 levels and more enemies on each lvl. Everything works.
Now I am working on getting music to play. one for the menu, one in game, and maybe game over screen. My AIM name is UrbanMcAaronson if you would like to help me that way….otherwise I will continue to scour the net aimlessly for a good tutorial on it.
July 16th, 2008 at 2:16 am
Alright, I did the best I could. My game is posted in the forum. Let me know what you think!
http://www.tutorialized.com/view/tutorial/How-to-make-a-simple-avoiding-game/36119
July 16th, 2008 at 2:18 am
wrong link. It’s in the forum under avoiding games.
July 16th, 2008 at 2:31 am
I don’t use AIM, apologies :)
If you have skype, I’m tdxiiifrozenhaddock on that.
July 16th, 2008 at 7:24 am
Tazzy!
You mean hit the player and -immediately- start going up?
Answer: Yes! =)
July 16th, 2008 at 8:30 am
Great tutorial! :D
I tried to make an avoiding game, but the character won’t move, I put the codes that you gave me on this website.
Sorry for bad English, I’m from Sweden
July 16th, 2008 at 4:24 pm
@Oskar
In thaaaat case, you’ll want something along these lines :)
onClipEvent (load) {
this._x = random(300);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
onClipEvent (enterFrame) {
this._y += speed;
if (this.hitTest(_root.player)) {
if(_root.lives==310){ //if lives are exactly equal to 310
speed = random(-5)-1; //set the speed to a minus number
this._y -= 10; //Jump the enemy upwards a bit so the player doesn’t hit it more than once.
}
}
Try that and see how it comes out, and comment again if you need any more help!
July 16th, 2008 at 4:27 pm
@Jon
Are you using ActionScript 2? It sounds like you have it set to AS3, and it won’t work with that. You can check under publishing settings, and you can change it there if need be :)
July 16th, 2008 at 4:35 pm
Hi, I don’t know if you still read the comments, but I just wanted to say that this is a great tutorial that taught me a lot about action scripting in Flash! :D
I also have a problem, and I’m wondering if you could help: Only the first enemy is killing my character. The others are just passing through. I copied all the other enemies from the first one by holding down the Ctrl-key and dragging, so they should be exactly alike. So I don’t understand this problem. It would be really nice if you could help (I also understand if this question has been asked a million times before and you’re just tired of answering. If that’s the case I am sorry) :)
-CookiemagiK
July 16th, 2008 at 4:50 pm
Course I read the comments, I’m here to help :)
Thanks for the praise! I’ll hopefully be adding a second tutorial to this, which should help people to add more features so if you have any suggestions for that I’d love to hear them!
As for your current problem, does your enemy have an instance name? If so, it shouldn’t do ;) (Or each enemy should have a different one)
That sounds like it’s the problem, give it a shot and tell me how it goes.
July 16th, 2008 at 5:12 pm
Hi!
Yes that was the problem. Everything is working great now!! \(^0^)/
Thanks again!
I don’t have any suggestion for your next tut. Since I’m really new to this, I still don’t know what’s possible to do with this powerful program. But I’ll definitely read it if you ever write one! :D
July 16th, 2008 at 5:20 pm
No worries!
Glad to be of help :)
July 16th, 2008 at 9:31 pm
hello im very new to flash and this is my very first game
I am having a bit of trouble with the character- ti wont die! Pls help :)
July 16th, 2008 at 9:49 pm
Hi!
Make sure you have an instance name on the player, and that it matches the one in the code exactly!
(As for double posting, I have to approve peoples comments until at least one is approved :))
July 17th, 2008 at 12:54 am
Suggestions on the next tutorial avoiding game.
Powerups
A coin/box that you have to collect to get to the next stage.
Maybe certain enemies that follow the character around.
Maybe an attack of some sort?
July 17th, 2008 at 1:00 am
Good ideas!
July 17th, 2008 at 1:29 am
what code are you talking about? is it the action script because there isnt a name in the actionscript
July 17th, 2008 at 2:19 am
No, no, no.
Under properties on the player, to the left, there is a box asking for an instance name :)
July 17th, 2008 at 2:58 am
still doesnt work :(
July 17th, 2008 at 3:27 am
Hmmm, do you want to email me the file and I’ll take a look?
(Gotta be Flash 8 or below)
July 17th, 2008 at 4:30 am
ok may i have ur email adress?
July 17th, 2008 at 4:53 am
Try downloading the source file and editing it from there.
July 17th, 2008 at 5:33 am
@qw3rty
alternateaccount [AT] frozenhaddock.co.uk
:)
July 17th, 2008 at 7:24 am
Apologies for dodgy email returns, my email doesn’t seem to like writing any text at the moment… I’ve attached the fixed file. It was an instance name issue, you had it at ‘character’ whilst the code had it as ‘player’ :)
July 17th, 2008 at 7:31 am
Tazzy! That worked out very well! But the enemey wont respawn! So I tried to make it respawn with this code:
onClipEvent (load) {
this._x = random(300);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
onClipEvent (enterFrame) {
this._y += speed;
if (this.hitTest(_root.player)) {
speed = random(-5)-1; //set the speed to a minus number
this._y -= 10; //Jump the enemy upwards a bit so the player doesn’t hit it more than once.
if (this._y<=100){
this._x = random(300);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
}
}
It didn’t turn out well =( =)
July 17th, 2008 at 7:41 am
onClipEvent (load) {
this._x = random(300);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
onClipEvent (enterFrame) {
this._y += speed;
if (this.hitTest(_root.player)) {
speed = random(-5)-1; //set the speed to a minus number
this._y -= 10; //Jump the enemy upwards a bit so the player doesn’t hit it more than once.
if (this._y<=-100){
this._x = random(300);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
}
Try that! You need it to be less than minus 100 :)
July 17th, 2008 at 9:04 am
Have an ETA on when the next tutorial might arise?
Or any other beginning flash tutorials that you recommend in the mean time?
I just did an OK shooter one, but it doesn’t really let me expand on it unless I know how to do my own AS.
July 17th, 2008 at 9:11 am
I shall point you toward http://jdog053.blogspot.com/2008/06/create-game-like-heavy-weapon-part-1.html (3 parts released as of writing) for a good tutorial that’ll help expand your knowledge.
As for an ETA… I shall try and get it close to finishing by today :)
July 17th, 2008 at 9:58 am
Tazzy… no… I’m sorry… I can’t make it work… It still doesn’t respawn…
July 17th, 2008 at 10:16 am
Aha, silly me ;)
onClipEvent (load) {
this._x = random(300);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
onClipEvent (enterFrame) {
this._y += speed;
if (this.hitTest(_root.player)) {
speed = random(-5)-1; //set the speed to a minus number
this._y -= 10; //Jump the enemy upwards a bit so the player doesn’t hit it more than once.
if (this._y< =-100 || this._y>=350){
this._x = random(300);//sets the horizontal position randomly
this._y = random(-50);//sets the y position above the stage
speed = random(5)+1;//sets the speed randomly
}
}
Now, THAT should work :)
July 17th, 2008 at 10:27 am
Thanks! It worked with some modification!
Here is my game: http://www.otechdesign.com/charlie.swf
Hehe :D It’s not finished… Please tell me what you think!
July 17th, 2008 at 10:28 am
The mission:
Get the white balls into the goal = 10pts
If you let a red ball into the goal = -10pts
Touch the red balls to make them go away
You have 20sec!
D:
July 17th, 2008 at 11:24 am
Nice! Looking good!
It looks like you’ve taken the ideas and used them to create a new game, which is excellent!
July 17th, 2008 at 11:28 am
Thanks =)
Yeah. I came up with the ideas as I read and tried out the tutorial! Thanks a lot for the tutorial, again! =)
The game is not so hard though… It doesn’t give the player a challenge…
July 17th, 2008 at 11:31 am
[...] in Flash, Games, Tutorials with No Comments Welcome to the first part of the second parts of the Avoiding game tutorial (Blimey, that’s a mouthful!) This tutorial will expand on the game you will have already made [...]
July 17th, 2008 at 11:49 am
Hmm… I cant get the player and the enemy to hit each other. They just slide tru and the movie stays on frame one.
Iv checked so that the names are the same in the script and the symbols, and as far as I can see they are!?
I even made a hole new “movie” with just some crappy drawn lines that were player and enemy, but the problem persisted.
//Ecce
July 17th, 2008 at 12:35 pm
Wohoo!
I’ve added a keeper to the game :D You can control the keeper with the arrow keys!
http://www.otechdesign.com/charlie_2.swf
Please note that I’ve never done anything like this before!
July 17th, 2008 at 5:09 pm
Hi, thanx for a cool tutorial.
My game just flipps like crazy between frame one and two… Everything seemd to work Ok untill I added the secont frame with the “game over” screen. I didnt ad the timer, but that cant have anything to do with it, right?
July 17th, 2008 at 6:14 pm
qwerty here again
how do i add music to the game? its a little boring without any mood :D and ty again tazz for your help with my “unable to die” stiuation
July 17th, 2008 at 8:34 pm
@Eric
No idea what’s wrong, do you want to email me the file so I can take a look?
@flipper
Make sure you have a stop(); action on both frames :)
@qw3rty
Music is a whole different tutorial ;) I’ll try to get one up soonish.
July 18th, 2008 at 9:27 am
Hi again… have been doing your tutorial over and over and over and over again, without getting the “kill” to work. By accident I klicked “test scene” instead of “test movie” and there the gameover workt just fine… so i tryed to export the file and run it outside of macromedia flash and it works just fine!
Strange!?
Well… apart from soundeffects and music there are a couple of features Id like to add to the game. First it wold be cool if u culd animate the enemies, so that they behave some way when they crash into out hero =)
I would also like the enemies only to be able to hit the player. What I mean is that theres a box around the player, and the enemy only have to hit this invisible box in order to launch the game-over frame. How do you make it so that its only just the charaters oulines that trigger the enemy?
Thanx alot again!
Ecce
July 18th, 2008 at 3:30 pm
That is strange indeed!
Soudeffects and music are going to be explained in a soon-to-be written tutorial :)
Animation of enemies will most definitely be in part 3 of this tutorial, if you check out part 2 then you’ll see a quick fix for the bounding box problem ;)
July 18th, 2008 at 8:27 pm
Yeah I can’t wait for 3. I will hopefully have my new game posted tonight. There will be a couple things I might ask if I can’t find other means to do it. I think you will be proud of this one!
July 18th, 2008 at 10:24 pm
Sounds awesome!
I’ll be glad to help with anything :)
July 19th, 2008 at 9:03 pm
hey tazzy your email is alternateaccount@frozenhaddock.