Custom controls
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access