我是Cocos2D的初学者。我想在特定的CCSprite上添加手势,但我在CCLayer上有手势。我的要求是在CCSprite上添加手势。怎么做?
我的代码:
-(id) initWithMask
{
CCSprite *mask=[CCSprite spriteWithFile:@"circle_mask.png"];
[self addChild:moveGlopFront z:1];
UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handlePushSceneGestureRecognizer:)];
[self addGestureRecognizer:swipeGestureRecognizer];
swipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
swipeGestureRecognizer.delegate = self;
}
-(void)handlePushSceneGestureRecognizer:(UISwipeGestureRecognizer*)aGestureRecognizer
{
for(CCNode *child in layer.children)
{
[child stopAllActions];
}
for(CCNode *child in layer.children)
{
[moveGlopFront setTexture:[moveGlopBack texture]];
[moveGlopFront runAction:[CCRepeatForever actionWithAction:[CCRotateBy actionWithDuration:5.0 angle:360]]];
}
}
答案 0 :(得分:0)
将手势识别器添加到图层中,并在手势识别器实现中使用CGRectIntersectsRect选择器检查是否触摸了sprite。