Game Development Reference
In-Depth Information
6. In onTouchMoved , we only need to move the cue body based on the position of
the player's finger. So we calculate the distance between the moving touch and the
white ball. If the cue body is still too close to the ball, we set its body object to
sleep and its texture object to invisible .
void GameLayer::onTouchMoved(Touch * touch, Event *
event) {
if (touch && touch == _touch) {
Point tap = touch->getLocation();
float diffx = tap.x -
_player->getPositionX();
float diffy = tap.y -
_player->getPositionY();
if (pow(diffx,2) + pow(diffy,2) <
pow(BALL_RADIUS * 2,2)) {
_usingCue = false;
_lineContainer->setDrawing(false);
_cue->setVisible(false);
_cue->getBody()->SetAwake(false);
} else {
_usingCue = true;
_cue->setVisible(true);
Search WWH ::




Custom Search