When you press the screen, drag, and then take your finger off the screen in any particular direction, it is called a swipe gesture. To detect such gestures, there are in-built functions in iOS and Cocos2d that can be used.
Before we start, it is better that we create a project and make the usual changes to the project so that it can load the MainScene
class and select images based on prefix names instead of folder names. As we have already done this in the previous chapters, it is redundant to repeat it. If you have problems, you can refer to the previous chapter and learn it well as we will be creating at least one new project for each chapter in the book.
The MainScene.m
file should look similar to the following:
#import "MainScene.h" @implementation MainScene +(CCScene*)scene{ return[[self alloc]init]; } - (void)onEnter{ [superonEnter]; self.userInteractionEnabled = YES; } - (void)onExit{ [superonExit]; self.userInteractionEnabled...