touch - Handle single tap on LayerColors in Cocos2d-x 3.0 -


I have a LayerColor subclass called MyLayer. I have some examples of MyLayer in the scene, I want to tap each example And just want to do something for that example.

I'm setting up touch handling like this:

  EventListenerTouchOneByOne * listener = EventListenerTouchOneByOne :: create (); Listener-> SetSwallowTouches (true); Audience & gt; OnTouchBegan = CC_CALLBACK_2 (MyLayer :: Touchback, this); Audience & gt; OnTouchEnded = CC_CALLBACK_2 (MyLayer :: touchEnded, this); Director: getInstance () - & gt; GetEventDispatcher () - & gt; addEventListenerWithSceneGraphPriority (listener, this);   

Then I handle touch with these methods: MyLayer :: touchBegan (touch * touch, event * event) {point touchpoint = It->; convertToNodeSpace (touch & gt; getLocation ()); This- & gt; Return the boundingbox () Point of view (touchpoints); } Zero MyLayer :: touchEnded (touch * touch, event * event) {}

The problem is not correctly stated for touching it works for a MyLayer instance, But other examples are never touched.

I have logged in the bounding box and touch point. The touch point and bounding box for touching the touch of MyLayer are "mixed": touch points that are in a bound box, are touched to touch for a different bounding box. That is why touchbags lie.

I am using Cocos-2D-X-3.0-RC1. Any help is appreciated!

In addition to this, touch handling for other layer subclasses works well with the same code of work. However, I have an example of those subclasses in my scene, whereas I have many examples of MyLayer

I think, to do the best, to rearrange your code a little bit, consider :

  auto listener = cocos2d :: EventListenerTouchOneByOne :: create (); listener-> SetSwallowTouches (true); Audience & gt; OnTouchBegan = [& amp; (cocos2d :: touch * touch, cocos2d :: Event * event) {return true; }; Audience & gt; OnTouchEnded = [=] (Cocos 2D :: Touch * Touch, Cocos 2D :: Event * Event) {MyLayer :: Touch Event (Touch); }; Zero MyLayer :: touchEvent (cocos2d :: touch * touch) {cocos2d :: point p = touch- & gt; GetLocation (); Cocos2d :: reactuct = it-> GetBoundingBox (); If (rect.containsPoint (p)) {// you touched it, do something now}}    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -