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 );}