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
Java 当变速器在发动机中时发生碰撞_Java_Android_Andengine_Physics_Game Physics - Fatal编程技术网

Java 当变速器在发动机中时发生碰撞

Java 当变速器在发动机中时发生碰撞,java,android,andengine,physics,game-physics,Java,Android,Andengine,Physics,Game Physics,我正在开发一个游戏和引擎。它的崩溃与非常恼人的错误信息。碰撞是在变换实体以更改位置时发生的。我正在使用body.setTransform方法更改位置。我的代码如下 public Scene onCreateScene() { this.mScene = new Scene(); this.mScene.setBackground(new Background(0, 0, 0)); this.mScene.setOn

我正在开发一个游戏和引擎。它的崩溃与非常恼人的错误信息。碰撞是在变换实体以更改位置时发生的。我正在使用body.setTransform方法更改位置。我的代码如下

    public Scene onCreateScene() {

            this.mScene = new Scene();
            this.mScene.setBackground(new Background(0, 0, 0));
            this.mScene.setOnSceneTouchListener(this);
            this.mScene.setOnAreaTouchListener(this);
            this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, 10), false);

            // Some Code.

            faceBox = new Sprite(bx, CAMERA_HEIGHT-mPlayerTextureRegion.getHeight()-25, this.mPlayerTextureRegion, this.getVertexBufferObjectManager());
            body = PhysicsFactory.createCircleBody(mPhysicsWorld, faceBox.getRotationCenterX(), faceBox.getRotationCenterY(), faceBox.getWidthScaled() * 0.6f, BodyType.DynamicBody, FIXTURE_DEF);//(this.mPhysicsWorld, faceBox, BodyType.DynamicBody, FIXTURE_DEF);
            body.setFixedRotation(true);
            body.setUserData("player");

            this.mScene.attachChild(faceBox);
            this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(faceBox, body, true, true));

            // Some Code.

            this.mEngine.registerUpdateHandler(new FPSLogger(){
            @Override public void onUpdate(float pSecondsElapsed) {
                try{
                        if(ball.getPosition().x<=n.getPosition().x&&ball.getPosition().y<body.getPosition().y-1.3f&&difficulty){
                            body.setTransform(ball.getPosition().x-0.6f<(l.getPosition().x+2*(l.getPosition().x-l.getWorldCenter().x)+0.83f)?(l.getPosition().x+2*(l.getPosition().x-l.getWorldCenter().x)+0.83f):ball.getPosition().x-0.6f,body.getPosition().y,body.getAngle());
                        }   
                }catch(Exception e){
                        e.printStackTrace();
                    }

            // Some Code.

            });
            }

        return this.mScene;
}
当您的物理世界被锁定时,它会崩溃。您应该使用isLocked方法检查是否已锁定。你的代码应该是使用这个

if(!mPhysicsWorld.isLocked())
    body.setTransform(ball.getPosition().x-0.6f<(l.getPosition().x+2*(l.getPosition().x-l.getWorldCenter().x)+0.83f)?(l.getPosition().x+2*(l.getPosition().x-l.getWorldCenter().x)+0.83f):ball.getPosition().x-0.6f,body.getPosition().y,body.getAngle());
if(!mPhysicsWorld.isLocked())
    body.setTransform(ball.getPosition().x-0.6f<(l.getPosition().x+2*(l.getPosition().x-l.getWorldCenter().x)+0.83f)?(l.getPosition().x+2*(l.getPosition().x-l.getWorldCenter().x)+0.83f):ball.getPosition().x-0.6f,body.getPosition().y,body.getAngle());