2

我是 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]]];
    }

}
4

1 回答 1

0

而是将手势识别器添加到图层中,并在手势识别器实现中使用 CGRectIntersectsRect 选择器检查您是否触摸了精灵。

于 2012-10-24T00:22:34.713 回答