Game Development Reference
In-Depth Information
Creating the pool table
In the debug draw view, this is what the table looks like:
All the elements seen here are created inside the initPhysics method in GameLay-
er.cpp . The table has no visual representation other than the background image we use in
the game. So there are no sprites attached to the individual pockets, for example.
The pocket bodies are created inside a for loop, with the best algorithm I could come
up with to distribute them correctly on screen. This logic is found in the initPhysics
method, so let's take a look at that and see how our first b2Body objects are created:
b2Body * pocket;
b2CircleShape circle;
float startX = _screenSize.width * 0.07;
float startY = _screenSize.height * 0.92f;
for (int i = 0; i < 6; i++) {
bodyDef.type = b2_staticBody;
if (i < 3) {
bodyDef.position.Set(startX/PTM_RATIO,
Search WWH ::




Custom Search