COCOS2DX Touch Response

Source: Internet
Author: User
Tags deprecated

Layer actually inherits the interface of touch control. So you just need to rewrite some functions. overriding in the Helloword class: virtual bool init (); /** Callback function for touch began.     ** @param touch touch information.* @param unused_event event information.* @return If return false, Ontouchmoved, ontouchended, ontouchcancelled'll never called.* @js NA    */ virtual bool Ontouchbegan (Touch *touch, Event *unused_event); /** Callback function for touch moved.     ** @param touch touch information.* @param unused_event event information.* @js NA    */ virtual void ontouchmoved (Touch *touch, Event *unused_event); /** Callback function for touch ended.     ** @param touch touch information.* @param unused_event event information.* @js NA    */ virtual void ontouchended (Touch *touch, Event *unused_event); /** Callback function for touch cancelled.     ** @param touch touch information.* @param unused_event event information.* @js NA    */ virtual void ontouchcancelled (Touch *touch, Event *unused_event);At this point, as long as the layer is on the interface, clicking will respond in these functions. You can control the movement of the sprite in this area but compile the error. 2>f:\cocos\p\demo\classes\gamescene.h: Error c2061:syntax error:identifier ' Touch ' (.. \classes\helloworldscene.cpp)2>f:\cocos\p\demo\classes\gamescene.h: Error c2061:syntax error:identifier ' Touch ' (.. \classes\helloworldscene.cpp)2>f:\cocos\p\demo\classes\gamescene.h: Error c2061:syntax error:identifier ' Touch ' (.. \classes\helloworldscene.cpp)2>f:\cocos\p\demo\classes\gamescene.h: Error c2061:syntax error:identifier ' Touch ' (.. \classes\helloworldscene.cpp)2>f:\cocos\p\demo\classes\gamescene.h: Error c2143:syntax error:missing '; ' Before ' * ' (.. \classes\helloworldscene.cpp)2>f:\cocos\p\demo\classes\gamescene.h: Error c4430:missing type Specifier-int assumed. Note:c++ does not support Default-int (.. \classes\helloworldscene.cpp)2>f:\cocos\p\demo\classes\helloworldscene.cpp: Warning C4996: ' cocos2d::ccstring ': was declared Deprecated2> f:\cocos\p\demo\cocos2d\cocos\deprecated\ccdeprecated.h (1108): See Declaration of ' cocos2d::ccstring ' /c0>2>f:\cocos\p\demo\classes\gamescene.h: Error c2061:syntax error:identifier ' Touch ' (.. \classes\gamescene.cpp)2>f:\cocos\p\demo\classes\gamescene.h: Error c2061:syntax error:identifier ' Touch ' (.. \classes\gamescene.cpp)2>f:\cocos\p\demo\classes\gamescene.h: Error c2061:syntax error:identifier ' Touch ' (.. \classes\gamescene.cpp)2>f:\cocos\p\demo\classes\gamescene.h: Error c2061:syntax error:identifier ' Touch ' (.. \classes\gamescene.cpp)2>f:\cocos\p\demo\classes\gamescene.h: Error c2143:syntax error:missing '; ' Before ' * ' (.. \classes\gamescene.cpp)2>f:\cocos\p\demo\classes\gamescene.h: Error c4430:missing type Specifier-int assumed. Note:c++ does not support Default-int (.. \classes\gamescene.cpp)2>f:\cocos\p\demo\classes\gamescene.cpp: Error C2065: ' Zxsprite ': undeclared identifier2>f:\cocos\p\demo\classes\gamescene.cpp: Error C2065: ' Zxsprite ': undeclared identifier2>f:\cocos\p\demo\classes\gamescene.cpp: Error c2227:left of '->setscale ' must point to class/struct/ Union/generic type2> type is ' Unknown-type '2>f:\cocos\p\demo\classes\gamescene.cpp: Error C2065: ' Zxsprite ': undeclared identifier2>f:\cocos\p\demo\classes\gamescene.cpp (): Error c2227:left of '->setposition ' must point to class/struct/ Union/generic type2> type is ' Unknown-type '2>f:\cocos\p\demo\classes\gamescene.cpp: Error C2065: ' Zxsprite ': undeclared identifier2>f:\cocos\p\demo\classes\gamescene.cpp: Warning C4996: ' cocos2d::layer::settouchmode ': was declared Deprecated2> f:\cocos\p\demo\cocos2d\cocos\2d\cclayer.h (181): See Declaration of ' Cocos2d::layer::settouchmode ' 2>f:\cocos\p\demo\classes\gamescene.cpp (): Error C2511: ' bool Gamescene::ontouchbegan (Cocos2d::touch *, Cocos2d::event *) ': Overloaded member function not found in ' Gamescene '2> f:\cocos\p\demo\classes\gamescene.h (4): See Declaration of ' Gamescene '2>f:\cocos\p\demo\classes\gamescene.cpp ($): Warning C4996: ' cocos2d::ccpoint ': was declared deprecated2> f:\cocos\p\demo\cocos2d\cocos\deprecated\ccdeprecated.h (833): See Declaration of ' Cocos2d::ccpoint ' 2>f:\cocos\p\demo\classes\gamescene.cpp (+): Error C2065: ' Zxsprite ': undeclared identifier2>f:\cocos\p\demo\classes\gamescene.cpp (+): Error c2227:left of '->setposition ' must point to class/struct/ Union/generic type2> type is ' Unknown-type '2>f:\cocos\p\demo\classes\gamescene.cpp: Error C2511: ' void gamescene::ontouchmoved (Cocos2d::touch *, Cocos2d::event *) ': Overloaded member function not found in ' Gamescene '2> f:\cocos\p\demo\classes\gamescene.h (4): See Declaration of ' Gamescene '2>f:\cocos\p\demo\classes\gamescene.cpp: Error C2511: ' void gamescene::ontouchended (Cocos2d::touch *, Cocos2d::event *) ': Overloaded member function not found in ' Gamescene '2> f:\cocos\p\demo\classes\gamescene.h (4): See Declaration of ' Gamescene '2>f:\cocos\p\demo\classes\gamescene.cpp: Error C2511: ' void gamescene::ontouchcancelled (Cocos2d::touch * , Cocos2d::event *) ': Overloaded member function not found in ' Gamescene '2> f:\cocos\p\demo\classes\gamescene.h (4): See Declaration of ' Gamescene 'Workaround: Add using_ns_cc under the Cocos2d.h inclusion path.#include "cocos2d.h" using_ns_cc; The method of registering touch responses in the < authoritative guide > is no longer supported in 3.x. In the authoritative guide is the need to overloadRegisterwithtouchdispatcher () function. But the 3.12 version I'm currently using is no longer supported.Because: there is the final keyword in the Layer.h source code. So I think I should just stop using it. (I don't know if I understand that) /** If istouchenabled, this method is called OnEnter. Override it to change theThe to Layer receives touch events.(Default:touchdispatcher::shareddispatcher ()->addstandarddelegate (this,0);)Example:void Layer::registerwithtouchdispatcher ()    {Touchdispatcher::shareddispatcher ()->addtargeteddelegate (this,int_min+1,true);    }@since v0.8.0@js NA    */ cc_deprecated_attribute virtual void registerwithtouchdispatcher () final {} ;



From for notes (Wiz)



COCOS2DX Touch Response

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.