Game Development Reference
In-Depth Information
(startY - i * (_screenSize.height * 0.84f * 0.5f))/
PTM_RATIO);
} else {
bodyDef.position.Set(
(startX + _screenSize.width * 0.85f)/PTM_RATIO,
(startY - (i-3) * (_screenSize.height * 0.84f *
0.5f))/PTM_RATIO);
}
pocket = _world->CreateBody(&bodyDef);
fixtureDef.isSensor = true;
circle.m_radius = (float) (1.5 * BALL_RADIUS) /
PTM_RATIO;
fixtureDef.shape = &circle;
pocket->CreateFixture(&fixtureDef);
auto pocketData = new b2Sprite(this, kSpritePocket);
pocket->SetUserData(pocketData);
}
The pocket bodies are static bodies and we determine in their fixture definition that they
should behave like sensors:
fixtureDef.isSensor = true;
This switches off all the physics from an object and turns it into a collision hot spot. A
sensor serves only to determine if something is touching it or not.
Tip
It's almost always best to ignore Box2D sensors and use your own sprites or points in your
collision logic. One neat feature in sensors is that they make it very easy to determine
when something has just ceased touching them, as you'll see once we cover contact listen-
ers.
Search WWH ::




Custom Search