Game Development Reference
In-Depth Information
_lineContainer->setDrawing(true);
placeCue(tap);
_cue->getBody()->SetAwake(true);
}
}
}
7. Otherwise, we awaken the body and call the placeCue method as follows:
void GameLayer::placeCue(Point position) {
float diffx = _cueStartPoint.x - position.x;
float diffy = _cueStartPoint.y - position.y;
float angle = atan2(diffy, diffx);
float distance = sqrt(pow (diffx, 2) + pow(diffy,
2));
_pullBack = distance * 0.5f;
Point cuePosition = Vec2(
_cueStartPoint.x - (BALL_RADIUS * 21 +
_pullBack) * cos(angle),
_cueStartPoint.y - (BALL_RADIUS * 21 +
_pullBack) * sin(angle)
);
_cue->getBody()->SetTransform(
b2Vec2(cuePosition.x/PTM_RATIO, cuePosition.y/
PTM_RATIO),
angle);
_lineContainer->setCuePoint(Vec2(
_cueStartPoint.x - ( _pullBack) * cos(angle),
_cueStartPoint.y - ( _pullBack) * sin(angle)));
}
This method then calculates the angle and position of the cue body and transforms
the cue's b2Body method accordingly. The SetTransform option of a
b2Body method takes care of both its position and angle.
8. Finally, in onTouchEnded , we let go of the cue body as follows:
Search WWH ::




Custom Search