Game Development Reference
In-Depth Information
12
DON'T HIT ME: COLLISION DETECTION
TECHNIQUES
CHAPTER OUTLINE
What You Can Do versus What You Need
227
HitTestObject—The Most Basic Detection
228
HitTestPoint—One Step Up 229
Radius/Distance Testing—Great for Circles
234
Rect Testing 235
The Enemy Class 236
The SimpleShooterCollisions Class Additions
237
Weaknesses of This Method 239
Pixel-Perfect Collision Detection
and Physics 241
When All Else Fails, Mix 'N Match
242
If you do much game development, you
ll eventually need to
determine when two objects on screen are colliding with one
another. Although Flash does not automatically notify you of this,
there are a number of different methods that can be used to detect
it. In this chapter, we
'
ll look at several types of collision detection
and in which scenarios they work best. We
'
ll also look at the strate-
gies that can be used with different styles of detection to achieve
the desired results.
'
What You Can Do versus What You Need
A temptation by some developers, particularly those coming from
other game-development backgrounds, is to always use the most
precise, robust collision detection in all situations. The problem
with this approach is the same that we discussed about physics in
the last chapter; using more than you need to create an illusion is
a waste of effort and computing power that could be used else-
where. The trick with collision detection is to identify the minimum
accuracy that you need to achieve a particular effect, and then
implement a system that works for that scenario. One good reason
 
 
Search Nedrilad ::




Custom Search