Game Development Reference
In-Depth Information
vector of movement; we'll need this when we collide the player with the puck.
The vector is based on the player's displacement.
3. In
onTouchesEnded,
we add this:
for (auto player : _players) {
if (player->getTouch() != nullptr &&
player->getTouch() == touch) {
//if touch ending belongs to this player, clear
it
player->setTouch(nullptr);
player->setVector(Vec2(0,0));
}
}
We clear the
_touch
property stored inside the player if this touch is the one just ending.
The player also stops moving, so its vector is set to
0
. Notice that we don't need the loca-
tion of the touch anymore; so in
TouchesEnded
you can skip that bit of logic.