Kobold2d:使用touchPhases进行KKInput触摸处理

时间:2013-05-13 07:10:26

标签: objective-c cocos2d-iphone kobold2d

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

-(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 ......这里发生了什么?

1 个答案:

答案 0 :(得分:0)

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

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