Cocos3.0 uses the genie to control the implementation of the touch events of the genie

Source: Internet
Author: User

Auto listener = EventListenerTouchOneByOne: create (); listener-> setSwallowTouches (true); auto sprite = this-> getChildByTag (virTag)-> getChildByTag (jumpTag ); listener-> listener = CC_CALLBACK_2 (MLayer: onTouchBegan, this); listener-> listener = CC_CALLBACK_2 (MLayer: onTouchMoved, this); listener-> onTouchEnded = CC_CALLBACK_2 (MLayer :: onTouchEnded, this); _ eventDispatcher-> addEventListenerWithSceneGraphPriority (listener, sprite); // this genie has the right to return true;} bool MLayer: onTouchBegan (Touch * touch, Event * event) {auto target = static_cast
 
  
(Event-> getCurrentTarget (); // obtain the current touch target (that hop genie) Point locationInNode = target-> convertToNodeSpace (touch-> getLocation ()); // convert the local coordinate system to the genie coordinate system (using the lower left corner of the genie as the coordinate origin) Size s = target-> getContentSize (); // obtain the sprite text size Rect rect = Rect (0, 0, s. width, s. height); // obtain the rectangle of the genie (starting from the lower left corner of the genie) if (rect. containsPoint (locationInNode) // determines whether the touch point is in the sprite rectangle. {auto sprite2 = this-> getChildByTag (cmsTag)-> getChildByTag (catTag ); sprite2-> setScale (0.2f);} return true;} void MLayer: onTouchMoved (Touch * touch, Event * event) {auto target = static_cast
  
   
(Event-> getCurrentTarget (); // obtain the current touch target Point locationInNode = target-> convertToNodeSpace (touch-> getLocation ()); // convert the local coordinate system to the genie coordinate system (using the lower left corner of the genie as the coordinate origin) Size s = target-> getContentSize (); // obtain the sprite text size Rect rect = Rect (0, 0, s. width, s. height); // obtain the rectangle of the genie (starting from the lower left corner of the genie) if (rect. containsPoint (locationInNode) // determines whether the touch point is in the sprite rectangle. {target-> setPosition (target-> getPosition () + touch-> getDelta ()); // set the captured genie coordinates to the place where the movement ends} void MLayer: onTouchEnded (Touch * touch, Event * event) {auto sprite2 = this-> getChildByTag (cmsTag) -> getChildByTag (catTag); sprite2-> setScale (0.6f );}
  
 


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.