2

我已经创建了一个游戏LibGDX,现在想在那里使用 SPen SDK。因此,当我创建SPenEventLibrary和设置侦听器时,它停止工作。我得到了反应onTouchFinger(我没有笔,这就是为什么我只使用这个事件),但是当我尝试将运动事件传播到 Stage诸如touchDownand之类的事件时touchUp- 它不起作用!

首先我得到视图,因为mSPenEventLibrary.setSPenTouchListener需要它:

TearTissue.libGDXView = initializeForView(new TearTissue(), config);

然后我扩展Stage类:

protected SPenEventLibrary mSPenEventLibrary;

public class MyStage extends Stage{

    public MyStage(float width, float height, boolean keepAspectRatio, SpriteBatch batch){
        super(width, height, keepAspectRatio, batch);
        final Stage localStage = this;

        mSPenEventLibrary = new SPenEventLibrary();

        mSPenEventLibrary.setSPenTouchListener(TearTissue.libGDXView, new SPenTouchListener() {

            @Override
            public boolean onTouchPenEraser(View arg0, MotionEvent arg1) {                  
                return false;
            }

            @Override
            public boolean onTouchPen(View arg0, MotionEvent arg1) {                    
                return false;
            }

            @Override
            public boolean onTouchFinger(View arg0, MotionEvent arg1) {   

                if(arg1.getAction()==MotionEvent.ACTION_DOWN){
                    localStage.touchDown((int)(arg1.getX()), (int)(arg1.getY()), 0, 0);                                             

                }
                if(arg1.getAction()==MotionEvent.ACTION_UP){                        
                    localStage.touchUp((int)(arg1.getX()), (int)(arg1.getY()), 0, 0);
                }
                return true;
            }

            @Override
            public void onTouchButtonUp(View arg0, MotionEvent arg1) {                  
            }

            @Override
            public void onTouchButtonDown(View arg0, MotionEvent arg1) {
            }
        });
    }       
    //DO SOME STUFF, THAT'S WHY I OVERRIDE IT       
    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {           
        return super.touchDown(screenX, screenY, pointer, button);
    }
    @Override
    public boolean touchDragged(int arg0, int arg1, int arg2) {         
        return super.touchDragged(arg0, arg1, arg2);
    }
    @Override
    public boolean touchUp(int arg0, int arg1, int arg2, int arg3) {            
        return super.touchUp(arg0, arg1, arg2, arg3);
    }       
}

我究竟做错了什么?任何帮助将不胜感激!

4

0 回答 0