【问题标题】:KKInput panningGesture giving wrong values when Iphone is tiltedKKInput panningGesture 在 Iphone 倾斜时给出错误的值
【发布时间】:2012-12-22 05:18:56
【问题描述】:

我正在使用来自 kobold2d 的 KKInput 使用平移手势识别器进行一些拖放操作。当 iphone 平放在桌子上时它工作得很好,但是如果我将手机向我倾斜,翻译似乎完全错误并且不再正常运行,实际上我认为我的 iPhone 似乎是颠倒的。

我是不是做错了什么?

示例代码:

if([input gesturePanBegan])
    {
        for( CCSprite* item in self.View.children )
        {
            bool result = [input isAnyTouchOnNode:item touchPhase: KKTouchPhaseAny];
            if (result)
            {
                itemPanning = item;
                originalPostion = item.position;

            }
        }
        CCLOG(@"%f y translation %f x translation", input.gesturePanTranslation.y , input.gesturePanTranslation.x);
        if(itemPanning != NULL)
        {
            [itemPanning setPosition:ccp(input.gesturePanTranslation.x + originalPostion.x, originalPostion.y)];
            if(input.gesturePanTranslation.x > 70)
            {
                [View Select: [itemPanning tag]];

                SelectAttackCommand * command = [SelectAttackCommand new];
                command.SelectedAttack = [itemPanning tag];

                itemPanning = NULL;

                NOTIFY(command);
            }
        }
    }
    else if(![input gesturePanBegan] && itemPanning != NULL)
    {
        itemPanning = NULL;
        [View Open];
    }

【问题讨论】:

    标签: cocos2d-iphone kobold2d


    【解决方案1】:

    这是一个答案,但可能不是最好的答案。在 KKInputGesture 中,handlePanGesture 下的平移值计算如下:

    gesturePanTranslation = [panRecognizer translationInView:glView]; gesturePanTranslation = [self convertRelativePointToGL:gesturePanTranslation];

    这里的第二个调用根据设备的方向转换一个值。这在某些情况下可能没问题,但在我的情况下不需要它,所以我将其注释掉,现在无论我如何倾斜 iPhone,我的翻译值总是正确的。

    不过,我可能在这里遗漏了一些东西,所以我还不想将其标记为答案。

    【讨论】:

    • 我已经注释掉了gesturePanTranslation -- = [self convertRelativePointToGL:gesturePanTranslation]; - 它仍然没有解决我同样的问题......嗯?
    • 倾斜手机仍然会破坏您的平移?
    • 是的。我认为这可能是我如何根据平移对对象进行更改的问题。如果您想提供帮助,请参阅:stackoverflow.com/questions/14668685/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2019-12-15
    • 2016-01-05
    相关资源
    最近更新 更多