• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 7. Controlling the Movie Clip > Detecting Movie-Clip Collisions

Detecting Movie-Clip Collisions

Another condition you can test for is whether a movie clip intersects another movie clip. For example, the game of Pong simply detects collisions between the ball, the paddles, and the wall, all of which are movie clips. Detecting movie-clip collisions can be useful on sophisticated e-commerce sites, as well. Say you develop an online-shopping site that lets your customers drag merchandise into a shopping cart. You can detect when the object intersects with the shopping cart and provide interaction such as highlighting the shopping cart or displaying the product price before the user drops the object.

Collision detection utilizes the movie-clip method hitTest. There are two ways to use hitTest. One is to check if the bounding boxes of any two movie clips intersect. The bounding box of a movie clip is the minimum rectangular area that contains the graphics. This method is ideal for graphics colliding with other graphics, such as a ball with a paddle, a ship with an asteroid, or a book with a shopping cart. In this case, you enter the target path of the movie clip as the hitTest argument—for example, hitTest(_root.target).


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint