使用C ++和SDL 2.0交换对象

时间:2016-06-28 17:15:39

标签: c++ sdl

我正在使用C ++和SDL开发游戏并遇到了一个我无法弄清楚的错误(在SDL或我的代码中)。 基本上我有一个宝石迷阵克隆,我有一个简单的功能来交换碎片(现在不看限制)。发生的事情是,只有当所选择的第一个具有比第二个更大的X或Y时,我能够交换这些部分,这转化为仅能够将它们交换或离开。 我来回检查了我的代码,甚至在调试时我可以看到交换正确完成,但我的第二个选定的部分继续选择,如果我按下板外或左侧或上方的一块,注册了新的交换。

我的代码如下

(...)
case SDL_MOUSEBUTTONDOWN:
            mCurrentSprite = BUTTON_SPRITE_MOUSE_DOWN;
            setPressed(true);
            gPressedButtons[pressedCount] = this;
            pressedCount++;
            if (pressedCount == 2)
            {
                swapSquares();
                pressedCount = 0;
                gPressedButtons[0]->setPressed(false);
                gPressedButtons[1]->setPressed(false);
            }
            break;
(...)
void swapSquares()
{
int tempType;
tempType = gPressedButtons[0]->getType();
gPressedButtons[0]->setType(gPressedButtons[1]->getType());
gPressedButtons[1]->setType(tempType);
if (tempType == gPressedButtons[1]->getType() || tempType1 == gPressedButtons[0]->getType())
{
    OutputDebugString(TEXT("swap done correctly\n"));
}
}

然后根据类型渲染碎片,这就是我交换它们的原因。知道这可能有什么问题吗?为什么它在某些情况下有效而在其他情况下无效?

0 个答案:

没有答案