So far, we have seen three different ways to move the character on the screen. There is one other way to add controls to our games, and that is using regular buttons. Remember the close button that we removed? We can create CCImageItems and CCMenu and make them call a function. In this function, we can write the logic for the movement of the character or any other function that we want the button to perform when it is clicked on.
So, as a practice, what we can do is create CCMenuItemImage in the init()
function, place it at 0.125 * visibleSize.width
and 0.125 * visibleSize.height
, and call the buttonControl()
function. As we are creating the game for devices with multiple resolutions, we never hardcode the values. So, we place the button at a distance of 1/8th the width in the x direction and at a y distance of 1/8 the height from the origin. For convenience, we can use the same CloseNormal.png
and CloseSelected.png
files:
CCMenuItemImage *pCloseItem = CCMenuItemImage::create...