Cocos2d-x-non-set layer class and non-set layer class subclass use touch

Source: Internet
Author: User

If the non-set layer class and its subclass want to use touch, the corresponding proxy should be inherited,

For example, in the TouchesTest folder of the test project, the class is inherited from CCSprite.

Instead of the Set layer class, it uses the proxy CCTargetedTouchDelegate

 


Unlike the set layer, the registration and logout of the touch proxy must be performed in OnEnter () and OnExit ().

 


Do not set the layer class and its subclass to use touch:


1. inherit the corresponding proxy. For example, in the TouchesTest folder of the test project, the Paddle. h inherits the proxy CCTargetedTouchDelegate.

2. Register and deregister the touch proxy in OnEnter () and OnExit ()

3. methods required for implementation: bool ccTouchBegan (CCTouch * touch, CCEvent * event) is required

 


For example, in the TouchesTest folder of the test project

 

  virtual void onEnter();    virtual void onExit();    virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);    virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);    virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
void Paddle::onEnter(){    CCDirector* pDirector = CCDirector::sharedDirector();    pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true);    CCSprite::onEnter();}void Paddle::onExit(){    CCDirector* pDirector = CCDirector::sharedDirector();    pDirector->getTouchDispatcher()->removeDelegate(this);    CCSprite::onExit();}    

 

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.