4

我是AndEngineonSceneTouchEvent的新手,我想用我的手指坐标画一条线t 检测到问题:/

    private Scene scene;
float startX;
float startY;
float lastX;
float lastY;
int lineUsageCount = 0;

@Override
    public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
        switch (pSceneTouchEvent.getAction()) {
        case MotionEvent.ACTION_DOWN:

            startX = pSceneTouchEvent.getX();
            startY = pSceneTouchEvent.getY();
            lineUsageCount = 0 ;

        break;
        case MotionEvent.ACTION_MOVE:

            lineUsageCount++;
            lastX = pSceneTouchEvent.getX();
            lastY = pSceneTouchEvent.getY();

        break;
        case MotionEvent.ACTION_UP:

            if (lineUsageCount <= 5) {
                final Line line = new Line(startX, startY, lastX,
                                lastY, this.getVertexBufferObjectManager());

                line.setLineWidth(1);
                line.setColor(255, 255, 255);
                scene.attachChild(line);

        }

        break;
    }   
    return true;
    }
};

它应该得到第一个坐标startX, startY,然后Action_Move它得到lastX, lastY并画线,但它似乎不起作用:|

4

1 回答 1

5

问题出在这行代码中:if (lineUsageCount <= 5) { 当您移动手指时,lineUsageCount将超过 5。调试此变量,然后在“IF”中更改它或从代码中删除此“IF”。

于 2013-01-02T07:23:26.137 回答