O'Reilly logo

The Essential Guide to Physics for Flash Games, Animation, and Simulations by Adrian Dobre, Dev Ramtal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Collision detection

Collisions are an inevitable fact of life in an animated world. So far, the movies we created do not know how to detect when two objects have collided or what to do when they do. This section focuses on the first issue: collision detection. Responding properly to collisions will be treated in detail in Chapter 11.

In general, collision detection can be a tricky problem, but if the objects to be tested are rectangular in shape, there is a very simple built-in method: hitTestObject().

Using the hitTestObject() method

The hitTestObject() method determines whether two display objects (such as sprites or movie clips) are in collision:

object1.hitTestObject(object2);

The outcome is a Boolean: it returns true if they do and false ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required