Adding hero controls
In the previous chapter, we added a small button in the screen where if the player tapped on that button, the hero created a bullet. That's quite good, but what we want is that whenever the player taps on the right-hand side of the screen, the rocket should fire. This is because the button is too small and the player wouldn't have much time to see where the button is located for him/her to tap on. We will also add a button on the left-hand side of the screen to boost the hero up whenever the button is tapped.
For this, let's make some changes to the HelloWorldScene.h
and HelloWorldScene.cpp
files. In the .h
file, remove void menuCloseCallback(CCObject* pSender);
and add a function named fireRocket()
under the spawnEnemy(float dt)
function:
void fireRocket();
Also, add two variables named leftButton
and rightButton
of the CCRect
type:
CCRect leftButton, rightButton;
Next, in the HelloWorldScene.h
file, you can remove the definition of the menuCloseBack()
function...