Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用模拟控制器旋转精灵_Android_Box2d_Andengine_2d Games_Google Play Games - Fatal编程技术网

Android 使用模拟控制器旋转精灵

Android 使用模拟控制器旋转精灵,android,box2d,andengine,2d-games,google-play-games,Android,Box2d,Andengine,2d Games,Google Play Games,您好,我正在开发一个游戏使用安引擎,现在我想我的精灵是旋转与屏幕上的alogcontroller。我已经初始化了它,但是现在我不知道如何完成剩下的工作。任何示例代码或任何东西都将不胜感激 提前谢谢 p.S旋转应该围绕精灵的轴。当我放开控制器时,我希望精灵朝向它旋转的方向,而不是最初的方向。对于精灵旋转,我们覆盖applyRotation()方法-> Sprite sprite = new Sprite(0, 0, textureRegionForMySprite, getVertexBuffer

您好,我正在开发一个游戏使用安引擎,现在我想我的精灵是旋转与屏幕上的alogcontroller。我已经初始化了它,但是现在我不知道如何完成剩下的工作。任何示例代码或任何东西都将不胜感激

提前谢谢


p.S旋转应该围绕精灵的轴。当我放开控制器时,我希望精灵朝向它旋转的方向,而不是最初的方向。

对于精灵旋转,我们覆盖applyRotation()方法->

Sprite sprite = new Sprite(0, 0, textureRegionForMySprite, getVertexBufferObjectManager()){
    @Override
    protected void applyRotation(GLState pGLState) {
        pGLState.rotateModelViewGLMatrixf(this.mRotation, 0, 1, 0);
    }
};

我用这个代码找到了一个解决方案

    mAnalogController = new AnalogOnScreenControl(90, cameraHeight - 130, mCamera, mControllerTextureRegion, mKnobTextureRegion, 0.01f, getVertexBufferObjectManager(), new IAnalogOnScreenControlListener(){

        @Override
        public void onControlChange(
                BaseOnScreenControl pBaseOnScreenControl, float pValueX,
                float pValueY) {

            //rect.registerEntityModifier(new RotationByModifier(0.5f, MathUtils.radToDeg((float) Math.atan2(-pValueX, pValueY))));

            rect.registerEntityModifier(new RotationModifier(0.1f, rect.getRotation(), MathUtils.radToDeg((float) Math.atan2(pValueX, -pValueY))));
        }

        @Override
        public void onControlClick(
                AnalogOnScreenControl pAnalogOnScreenControl) {
            // TODO Auto-generated method stub

        }

    });

唯一的问题是当我释放控制器时,它会回到初始位置并旋转,这不是我想要的。有什么想法吗?

我不太了解如何用analogController实现这一点。我应该这样做,然后在AnalogOnScreenController上的onControlChange上添加EntityModifier吗?我想我会试试的,但是更详细的解释会更好。谢谢