Cocos2D for iPhone application development

Source: Internet
Author: User

Cocos2DForIPhoneApplication Development Learning is what we will introduce in this article.Cocos2DLet's look at the content.

Except that the Layer can accept touch events, a new feature is added after Cocos2D 0.8 so that all objects can accept touch events. I don't know how to use this method. Here is a brief introduction.

First, add the event receiver:

 
 
  1. [[TouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:NO]; 

// Self is the receiver. The smaller the priority parameter is from 0, the higher the priority is, the more events are received first. The last parameter indicates whether the event is blocked.

Then three methods are implemented:

 
 
  1. # Pragma mark TouchDispatcherDelegate
  2. -(BOOL) ccTouchBegan :( UITouch *) touch withEvent :( UIEvent *) event {
  3. // Your code
  4. Return YES; // if NO is returned here, this touch will be ignored.
  5. }
  6. -(Void) ccTouchMoved :( UITouch *) touch withEvent :( UIEvent *) event
  7. {
  8. // Your code
  9. }
  10. -(Void) ccTouchEnded :( UITouch *) touch withEvent :( UIEvent *) event {
  11. // Your code
  12. }

In this way, coco2d can be processed just like events in UIView.

Edit: Don't forget to delete the listener, or else ......

 
 
  1. [[TouchDispatcher sharedDispatcher] removeDelegate:self]; 

Summary:Cocos2DForIPhoneI hope this article will be helpful to you!

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.