Reputation: 19767
Imagine three instances of a CCLayer
subclass Block
positioned next to each other. Each is 100x100 pixels and has some basic square background art. These three objects are part of an encapsulating CCLayer
subclass called Container
.
How can I swipe across the three Blocks and detect the swipe/tap/touch for each Block in Container?
If the problem was constrained to just handling taps on Block
s in Container
then one could use a delegate. Something like BlockDelegate
with a required method userTappedBlock:(Block *) b
which would inform the Container
whenever a Block
is tapped.
However this approach hasn't worked for swiping yet. I get the callback in Container
but only for the first Block
that's tapped.
Upvotes: 0
Views: 126
Reputation: 427
In CustomLayer.cpp write this method for tapping the layer
void CustomLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
CCTouch *touch = (CCTouch *) pTouches->anyObject();
CCPoint location = touch->getLocationInView();
location = CCDirector::sharedDirector()->convertToGL(location);
if(layer->boundingBox().containsPoint(location))
CCLog("layer Hit Test");
}
Upvotes: 0
Reputation: 10860
You can handle touches in layer, that contains your blocks. Then, in touchEnded:WithEvent:
method check what block contains touch's position.
Upvotes: 1