Game Development Reference
In-Depth Information
void GameLayer::onTouchEnded(Touch* touch, Event*
event) {
if (_usingCue && _touch) {
auto cueBody = _cue->getBody();
float angle = cueBody->GetAngle();
//release cue!
cueBody->ApplyLinearImpulse(
b2Vec2 (_pullBack * cos(angle) *
SHOT_POWER,
_pullBack * sin(angle) * SHOT_POWER),
cueBody->GetWorldCenter());
}
_usingCue = false;
_touch = nullptr;
_lineContainer->setDrawing(false);
}
We use ApplyLinearImpulse . This method receives a vector for the impulse
to be applied and the position on the body where this impulse should be applied.
The _pullback variable stores the information of how far the cue body was
from the ball when the player released the cue body. The farther it was, the
strongest the shot will be.
Search WWH ::




Custom Search