首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何实现if else语句的Kobold2D KKInput gestureSwipeDirection?

如何实现if else语句的Kobold2D KKInput gestureSwipeDirection?
EN

Stack Overflow用户
提问于 2013-05-19 08:04:12
回答 1查看 90关注 0票数 0

我发现很难从文档中了解如何使用Kobold2D KKInput gestureSwipeDirection来检测向左/向右/向上/向下滑动,并让它们执行if else语句。有没有人可以帮我提供一个示例代码。谢谢

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-20 22:16:28

我认为您正在犯一个错误,您将代码放在一个方法中,但是您应该使用两只手,一只手用于确定KKInput,另一只手用于检查状态,而且您还忘记了gestureSwipeEnabled

尝试这样做:

代码语言:javascript
复制
-(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;
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16630205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档