(帮助)AndEngine - 使用触摸移动

时间:2013-11-07 21:56:09

标签: touch andengine sprite move

嘿伙计们关注此代码

final AnimatedSprite mySprite = new AnimatedSprite(100, 220, this.mySpriteTextureRegion) {
            @Override
            public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
                this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
                        int eventaction = event.getAction(); 

                    float X = event.getX();
                    float Y = event.getY();

                    switch (eventaction) {
                       case TouchEvent.ACTION_DOWN:
                    break;
                       case TouchEvent.ACTION_MOVE: {
                            this.setPosition(X, Y);
                            break;}
                       case TouchEvent.ACTION_UP:
                            break;
                    }
            return true;
        }
    };

但使用Sprite而不是AnimatedSprite

但是当我在我的手机上测试时,精灵不会移动......

我做错了什么?

1 个答案:

答案 0 :(得分:1)

你错过了吗?

registerTouchArea(mySprite);
setTouchAreaBindingOnActionDownEnabled(true);