{loadposition adposition4}
Stage 3 – Collision Detection
In the previous stages of game development, we created a catching character that moves based keyboard controls. We created falling objects that are placed on the stage dynamically with Actiosncript code, are placed in random places on the x axis, and fall at random speeds along the y axis.
{loadposition adposition5}Now, in this stage, we need to create the collision detection Actiosncript game code which will enable our catching character to catch the falling objects when he gets close enough to them to cause a collision. To do this we will run a constantly repeating test (polling) that will compare the x and y position of the falling objects to the x and y position of the catching character.
I have created video tutorials below that explain the Actionscript collision detection code and process in detail.
Video Tutorials
In part 7, I add that code that will compare the x and y positions of the moviecips to detect a collision.
In part 8, a successful collision increases the game score and also activates a sound effect.
{loadposition adposition4}
Older Video Tutorials
The video tutorials below were created with an earlier version of Flash and Actionscript 2. The videos are still good and Parts 1 and 2 cover how to use the Flash hitTest function (not covered above) as an alternative for the collision detection. Also included below, is how to add a Flash pre-loader at the beginning of your catching game
- Flash Catching Game – collision detection Part 1 – hitTest() collision detection
- Flash Catching Game – collision detection Part 2 – hitTest() collision detection part 2
- Flash Catching Game – collision detection Part 3 – includes adding sound
- Flash Catching Game – collision detection Part 4 – comparing x and y positions, a better method of collision detection
- How to Create a Flash Preloader Part 1 – Catching Game,
- How to Create a Flash Preloader Part 2 – Catching Game,
- Here are the sample files for you to refer to: sample_files.zip