Adding the controls
We have the code in place to add and remove platforms based on the user's touch. So it's time to code the touch controls for the game. Let's look at the ccTouchesBegan
function in GameWorld.cpp
:
void GameWorld::ccTouchesBegan(CCSet* set, CCEvent* event) { // don't accept touch when clown is in these states if(clown_->GetState() == E_CLOWN_ROCKET || clown_->GetState() == E_CLOWN_BALLOON || clown_->GetState() == E_CLOWN_UP) return; CCTouch* touch = (CCTouch*)(*set->begin()); CCPoint touch_point = touch->getLocationInView(); touch_start_ = CCDirector::sharedDirector()-> convertToGL(touch_point); // remove any previously added platforms RemovePlatform(); // convert touch coordinates with respect to game_object_layer_ and position the platform there platform_->setPosition(game_object_layer_-> convertToNodeSpace(touch_start_)); platform_->setVisible(true); platform_->setScaleX(0); }
We start by storing...