Какова позиция свойства Scene, Velocity в PhysicsHandler?

Я новичок в программировании для Android с помощью Andengine framework. И я учусь с помощью руководств в Интернете. Я не знаю, я неправильно понимаю корневую позицию свойства Scence и Velocity в PhysicsHandler.

Здесь: введите здесь описание изображения

И если мое мнение верно. Таким образом, как установить свойство Velocity в PhysicsHandler, чтобы оно соответствовало положению сцены?

Это мой пример: введите здесь описание изображения

И мой код:

scene.setOnSceneTouchListener(new IOnSceneTouchListener() {
            @Override
            public boolean onSceneTouchEvent(Scene pScene,
                    TouchEvent pSceneTouchEvent) {
                if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) {
                    positionUpX = pSceneTouchEvent.getX();
                    positionUpY = pSceneTouchEvent.getY();

                    ball = new Ball(positionDownX, positionDownY, positionUpX,
                            positionUpY, mFaceTextureRegion,
                            getVertexBufferObjectManager());
                    scene.attachChild(ball);
                    return true;
                }
                if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
                    positionDownX = pSceneTouchEvent.getX();
                    positionDownY = pSceneTouchEvent.getY();

                    return true;
                }
                return false;
            }
        });




private static class Ball extends AnimatedSprite {
        private final PhysicsHandler mPhysicsHandler;

        public Ball(final float pDownX, final float pDownY, //Start 
                final float pUpX,final float pUpY, //End
                final TiledTextureRegion pTextureRegion,
                final VertexBufferObjectManager pVertexBufferObjectManager) {
            super(pDownX, pDownY, pTextureRegion, pVertexBufferObjectManager);
            this.mPhysicsHandler = new PhysicsHandler(this);
            this.registerUpdateHandler(this.mPhysicsHandler);
            this.mPhysicsHandler.setVelocity(pUpX, pUpY);
        }

        @Override
        protected void onManagedUpdate(final float pSecondsElapsed) {
            if (this.mX < 0) {
                this.mPhysicsHandler.setVelocityX(BALL_VELOCITY);
            } else if (this.mX + this.getWidth() > CAMERA_WIDTH) {
                this.mPhysicsHandler.setVelocityX(-BALL_VELOCITY);
            }
            if (this.mY < 0) {
                this.mPhysicsHandler.setVelocityY(BALL_VELOCITY);
            } else if (this.mY + this.getHeight() > CAMERA_HEIGHT) {
                this.mPhysicsHandler.setVelocityY(-BALL_VELOCITY);
            }
            super.onManagedUpdate(pSecondsElapsed);
        }
    }

person LazyCatIT    schedule 22.04.2014    source источник


Ответы (1)


Я нашел ответ с помощью Physics Box2D и Mouse Joint

person LazyCatIT    schedule 23.04.2014