Recently there are children's shoes asked me how to get to the iphone screenshot of the event, so this article will simply talk about how to deal with this problem.
In the COCOS2DX engine, we can obtain in Appdelegate, the user will apply into the background, and return to the application of the event function. So the corresponding, COCOS2DX also in the engine gives us to intercept the screen and other such only mobile phone should have event processing function.
In fact, everyone should be very familiar with the function of intercepting user touch screen, as follows:
1234 |
//default implements is used to call script callback if exist
virtual
bool cctouchbegan (Cctouch *ptouch, ccevent *pevent);
virtual
void cctouchmoved (Cctouch *ptouch, ccevent *pevent);
virtual
void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
|
As above three functions:
1.touchBegan: Gets the function of the user just touching the screen event.
2.touchMoved: Gets the function of the user sliding screen event.
3.touchEnded: Gets the function of the user leaving the screen event.
In fact, the details of children's shoes, or do not understand the children's shoes may have seen, in fact, touch screen event also has a function can inherit rewrite:
virtual void cctouchcancelled (Cctouch *ptouch, ccevent *pevent);
This function touchcancelled the function of getting an unexpected event to cancel a touch-screen event. In fact, this function can not only get screenshots and other accidents caused by the touch screen cancellation of events, but also effectively avoid the multi-contact between the problems caused by program anomalies.
In addition Himi recommend rewriting the touchscreen function, be sure to rewrite the cctouchcancelled function to avoid unexpected events, causing the program to crash!
"Cocos2d-x notes" COCOS2DX get phone screenshots and other accidental cancellation of touch screen event processing Method!