0

我发现很难从文档中学习如何使用 Kobold2D KKInput gestureSwipeDirection 来检测向左/向右/向上/向下滑动并让它们执行 if else 语句。任何人都可以通过向我提供示例代码来提供帮助。谢谢

KKInput* input = [KKInput sharedInput];
KKSwipeGestureDirection dir = input.gestureSwipeDirection;
switch (dir)
{
    case KKSwipeGestureDirectionRight:
        // direction-specific code here
        break;
    case KKSwipeGestureDirectionLeft:
        // direction-specific code here
        break;
    case KKSwipeGestureDirectionUp:
        // direction-specific code here
        break;
    case KKSwipeGestureDirectionDown:
        // direction-specific code here
        break;
}
4

1 回答 1

0

我认为你犯了一个错误,你将代码放在一个方法中,但你应该用两只手,一只确定 KKInput,一只检查状态,再加上你忘了gestureSwipeEnabled

尝试这样做:

-(id) init {

    if ((self=[super init])) {

        input = [KKInput sharedInput];
        input.gestureSwipeEnabled = YES;

        [self schedule:@selector(theTime:)];

    }
    return self;
}

-(void) theTime:(ccTime)time {

    if (input.gestureSwipeRecognizedThisFrame) {

        KKSwipeGestureDirection dir = input.gestureSwipeDirection;
        switch (dir)
        {
            case KKSwipeGestureDirectionRight:
                // direction-specific code here
                break;
            case KKSwipeGestureDirectionLeft:
                // direction-specific code here
                break;
            case KKSwipeGestureDirectionUp:
                break;
            case KKSwipeGestureDirectionDown:
                // direction-specific code here
                break;
            default:
                break;
        }
    }
}
于 2013-05-20T14:16:28.063 回答