Internet Commerce

Partners & Affiliates

Developer Channel


Featured Flash FLA
Gallery Downloads 11401 Flash Movies | 5 New Flash Movies Added
What's New | Top 100

Featured FLA

»  Author Miguel Panos
»  Title: Tarta
»  Description: It is a circle graph or pie chart that takes the data entered by user
»  More by Miguel Panos


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 4839 Flash Sites | 1 New Flash Links
What's New | Top 100 Flash Site

Featured Site

»  AuthorDeft Creative Ltd
»  Link: Home Page
»  Description: Portfolio site for .DeftCreative Ltd. A UK based web design studio specialising in flash websites, games and interactive CDROMs. With an emphasis on making things different.


Random Links | Add your own Flash Related Links
Flash Tutorials 1484 Tutorials 7 New Tutorials Added!
What's New | Top100

» Making Automatic Training Screen Capture Easily
» Create Undersea Life Animation
» Making Deinterlace Video with a low bitrate Easily
» How To Make A Simple Animation Using Christmas Clips
» Simple Step by step flash game tutorial Spot the diffrence
» How To Make A Moving Text Slide
» Create Flash Banner With Text Float Effect
» How To Make Zoo Photos Slideshow
» How To Make A Dolphin Photos Slideshow
» Unknown Tag: Title10
Random Tutorial | Add Site


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Actionscripting

Categories "hitTest" action for Games!
Author: Jason

 
Page 1
1

Key:

MC= MovieClip

What you will learn in this tutorial:

You will learn how to use the "hitTest" action and how to make something happen once the hitTest it true. In this case it will make the dynamic text box named health to -20.

Getting Started!

First open a new .FLA file so you can follow with me. Now once the .FLA is done loading make a circle just don't make it really big. Make this into a MC and give it any name you want. Now go down to properties and go to where it says "" and change it to "enemy" (take out the "'s though.) make another circle and put it as a MC. For the instance name for this one name it "man". Put the man on the left side and the enemy on the right side of the stage.

Now for the enemy put these codes in:
onClipEvent (enterFrame) {
 if (this.hitTest(_root.man)) {
 _root.health -= 20;
 if (_root.health== 0) {
 _root.gotoAndStop(2);
 }
 }
}
The onClipEvent performs an action when a particular "Movie Clip" event occurs. The "if (this.hitTest(_root.man)) {" means that "if" a certian thing will happen to "this" movieclip which this certain thing is a hitTest which tells you if it hits something. "_root." means that the thing the hitTest is going to look for is the "man". "_root." comes in play again... This time it tells the dynamic text box named "health" to go down 5. now the next line under it tells "if" the health reaches 0 it will "gotoAndStop" at frame 2. so it looks like "gotoAndStop(2);" .... Easy huh?

Ok now make a dynamic text box and give it the "var" name of "health". Put it up like it the right top of the stage.

Now double click on the enemy and create a motion tween for frame 1.
Make a keyframe around frame 25-30. Make the enemy pass through the man so the hitTest can do it's thing.

Almost done!

Go to the actions for Frame 1 and put these codes in:

stop();
health=100

"stop();" stops your movie or game at that frame. "health=100" means to set the dynamic text box named "health" to have the value of 100.

Now go to frame 2 and add a keyframe there and add anything you want to it cause this frame comes in when your health hits 0.

Now if you want to make a button that leads you to frame 1 add these codes to the button:
on (release){
 _root.gotoAndStop(1);
 resetVariables==health;
}
Yay! We are done, test your movie and wait for your enemy to hit your man... Once they collide the health should go down 20.
Once it hits 0 it should stop you at frame 2. Now try out your play button to make sure it works properly. If it does it will bring you at frame 1 and you will have 100 health. I hope this helped! Good luck on actionscripting in the future!

1

» Level Intermediate

Added: : 2004-02-17
Rating: 6.35 Votes: 33
Hits: 1487
» Author
Jason is pretty decent at actionscript and flash and still learning as he goes along.
» Download
Download the files used in this tutorial.
Download (32 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments