0

我不完全理解这一点,我正在尝试使用默认模板设置触摸处理,我所做的唯一区别是我将如何处理触摸委托给实现协议的类。问题是唯一kTouchPhase有效的是kTouchPhaseCancelled.

-(void) update:(ccTime)delta
{
    if ([input isAnyTouchOnNode:self touchPhase:KKTouchPhaseAny])
    {

        CCLOG(@"Touch: beg=%d mov=%d sta=%d end=%d can=%d",
              [input isAnyTouchOnNode:self touchPhase:KKTouchPhaseBegan],
              [input isAnyTouchOnNode:self touchPhase:KKTouchPhaseMoved],
              [input isAnyTouchOnNode:self touchPhase:KKTouchPhaseStationary],
              [input isAnyTouchOnNode:self touchPhase:KKTouchPhaseEnded],
              [input isAnyTouchOnNode:self touchPhase:KKTouchPhaseCancelled]); 
    }

    CCDirector* director = [CCDirector sharedDirector];

    if (director.currentPlatformIsIOS)
    {
        [self gestureRecognition]; // Calls method pasted bellow

        if ([KKInput sharedInput].anyTouchEndedThisFrame)
        {
            CCLOG(@"anyTouchEndedThisFrame");
        }
    }

.->

-(void) gestureRecognition
{
    NSAssert(self.delegate != nil, @"Delegate must be non-nil");

    if (input.gestureTapRecognizedThisFrame)
    {
        [self.delegate moveObjectToNewPosition:input];
    }

然后实现协议的委托决定在其中做什么moveObjectToNewPosition:

-(void) moveObjectToNewPosition:(KKInput *)input
{
    //KKInput *input = [KKInput sharedInput];
    CGSize screenSize = [[CCDirector sharedDirector] winSize];

    CGPoint touchLocation = [input locationOfAnyTouchInPhase:KKTouchPhaseBegan];
    [self touchesBegan:touchLocation];

}


- (void)touchesBegan: (CGPoint)touchLocation
{
    CCLOG(@"x: %f y: %f", touchLocation.x, touchLocation.y);
}

但是给我坐标的唯一触摸阶段是KKTouchPhaseCancelledKKTouchPhaseAny......这里发生了什么?

4

1 回答 1

0

手势识别器捕获触摸事件,特别是点击识别器实际上会检测到任何触摸(大多数触摸是点击),因此您看不到任何其他触摸事件(阶段)但取消。

要解决此问题,请使用点击手势的位置属性,而不是任何触摸的位置。

于 2013-05-13T08:11:25.177 回答