Hard work and perseverance.
Add delegate
Addstandarddelegate ();
Turn on multi-touch
Settouchenabled ();
Touch Screen Event:
1. Register Multi-Touch
virtual void registerwithtouchdispatcher (void);
2. callback function that responds when the user first touches the phone screen
virtual void Cctouchesbegan (Ccset * touchs,ccevent * event);
3. Response callback function when the user's finger is sliding on the phone screen
virtual void cctouchesmoved (Ccset * touchs,ccevent * event);
4. callback function that responds when the user's finger leaves the phone screen
virtual void cctouchesended (Ccset * touchs,ccevent * event);
5. Add the open multi-touch code in the appcontroller.mm Didfinishlaunchingwithoptions method. As follows:
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {//Ove
Rride point to Customization after application launch.
ADD The View controller ' s view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainscreen] bounds]]; Eaglview *__glview = [eaglview viewwithframe: [Window bounds] Pixelformat:keaglcolor FormatRGBA8 depthformat:gl_depth_component16 PRESERVEB
Ackbuffer:no Sharegroup:nil Multisampling:no
NUMBEROFSAMPLES:0]; [__glview Setmultipletouchenabled:yes]; Add this code//use Rootviewcontroller manage Eaglview viewcontroller = [[Rootviewcontroller alloc] Initwithnibname:ni
L Bundle:nil];
Viewcontroller.wantsfullscreenlayout = YES; Viewcontroller.view = __glview; Set Rootviewcontroller to Window if ([[Uidevice currentdevice].systemversion Floatvalue] < 6.0) {/
/Warning:addsubview doesn ' t work on iOS6 [window AddSubview:viewController.view];
} else {//Use this method on IOS6 [window Setrootviewcontroller:viewcontroller];
} [window makekeyandvisible];
[[UIApplication sharedapplication] setstatusbarhidden:yes];
Cocos2d::ccapplication::sharedapplication ()->run ();
return YES; }
. cpp Simple case:
#include "HelloWorldScene.h" #include "SimpleAudioEngine.h" using namespace cocos2d;
using namespace Cocosdenshion;
ccscene* Helloworld::scene () {Ccscene *scene = Ccscene::create ();
HelloWorld *layer = Helloworld::create ();
Scene->addchild (layer);
return scene; } bool Helloworld::init () {if (!
Cclayer::init ()) {return false;
}//Turn on multi-touch this->settouchenabled (TRUE);
return true; }//Register multi-Touch void Helloworld::registerwithtouchdispatcher (void) {//Register monitor ccdirector::shareddirector ()->gettouchd
Ispatcher ()->addstandarddelegate (this,0);
} void Helloworld::cctouchesbegan (Ccset *ptouches, ccevent *pevent) {Ccsetiterator it;
Cctouch* Touch; Here it is equivalent to the number of system allocations,//ptouches->begin () gets the first digit//ptouches->end () is the last for (it = Ptouches->begin (); it ! = Ptouches->end ();
it++) {touch = (cctouch*) (*it);
if (!touch) break; Cclog ("Began id = =%d ", Touch->getid ());
}} void Helloworld::cctouchesmoved (Ccset *ptouches, ccevent *pevent) {Ccsetiterator it;
Cctouch* Touch;
for (it = Ptouches->begin (); It! = Ptouches->end (); it++) {touch = (cctouch*) (*it);
if (!touch) break;
Cclog ("Moved id = =%d", Touch->getid ());
}} void Helloworld::cctouchesended (Ccset *ptouches, ccevent *pevent) {Ccsetiterator it;
Cctouch* Touch;
for (it = Ptouches->begin (); It! = Ptouches->end (); it++) {touch = (cctouch*) (*it);
if (!touch) break;
Cclog ("Ende id = =%d", Touch->getid ()); }}//write on life cycle function void Helloworld::onenter () {cclayer::onenter ();} void Helloworld::onexit () {Ccdirector::sharedd
Irector ()->gettouchdispatcher ()->removedelegate (this);
Cclayer::onexit ();
}