[IOS-Cocos2d game development 6] To touch screen event additional explanation, solve the failure to trigger the cctouchmoved event [important!]

Source: Internet
Author: User

Li huaming himiOriginal, reprinted must be explicitly noted:
Reprinted from[Heimi gamedev block]Link: http://www.himigame.com/iphone-cocos2d/453.html

The previous section describes how to use two methods to monitor the user's touch screen;

The main problem to be discussed is the use of registration listening (event allocation to listen to touch screens). As mentioned in the previous chapter, registration is required first:Code:

 
// Register an independent touch event [[cctouchdispatcher shareddispatcher] addtargeteddelegate: Self priority: 0 swallowstouches: Yes];

If multiple listeners are registered, you can set them based on the priority parameter. The higher the value of this parameter, the lower the priority. Assume that XX and YY have registered the listener, if the XX priority is greater than YY, the XX listening function is first entered;

If you use the preceding method to listen to the following events:

-(Bool) cctouchmovan :( uitouch *) touch withevent :( uievent *) event {return no;}-(void) cctouchmoved :( uitouch *) touch withevent :( ui* event *) event {}-(void) cctouchended :( uitouch *) touch withevent :( uievent *) event {}

If yes is returned from the cctouchbegan function in XX, the listener function in another listener (yy) is not responded. This is described in the previous chapter. However, this is exactly what we want to talk about, if you want both XX and YY to listen to events, both of them can return no in cctouchbegan, but if you want to process the cctouchmoved mobile event function in YY or XX, you will find that XX and YY do not respond to their functions, because when you retrun no;, although the Code between cctouchbegan and return is executed, however, your return no actually tells cocos2d to discard the event processing, so that cocos2d can continue to allocate touch-screen events to other registered classes to process the listener until the end or cocos2d gets return true;

Solution: for example, if you want to listen to the cctouchmoved event in the YY class, in order not to affect the monitoring of the cctouchbegan event in XX, you should set the priority of the XX class to be higher than that of the YY class when registering the listener, and the cctouchbegan function return no in the XX class. After the user touch screen, first, go to the XX class to process the event, and then (because the XX class return no) enter the YY class. Then, In the cctouchbegan function of the yy class, the return yes; in this way, cocos2d can respond to the cctouchmoved function;

If you want XX and YY classes to respond to the cctouchmoved function, at least I cannot implement this event allocation method. I don't know if it is a bug left by cocos2d 1.0 or another cause, I came across today and shared it with you;

OK, it's time to go to bed. Good night everyone ~ ~~~~~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.