【问题标题】:Crash when transorm body in AndEngine在 AndEngine 中转换车身时崩溃
【发布时间】:2015-03-17 05:49:17
【问题描述】:

我正在开发一款游戏和引擎。它因非常烦人的错误消息而崩溃。当变换身体改变位置时会发生崩溃。我正在使用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;
}

来自 logcat 的错误日志是。

 03-03 13:02:16.374: A/libc(5892): /Users/ngramlich/Workspace/gdk/graphic_engines/AndEngine/AndEnginePhysicsBox2DExtension/jni/Box2D/Dynamics/b2Body.cpp:395: void b2Body::SetTransform(const b2Vec2&, float32): assertion "m_world->IsLocked() == false" failed
 03-03 13:02:16.375: A/libc(5892): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 5936 (Thread-474)

【问题讨论】:

    标签: java android andengine physics game-physics


    【解决方案1】:

    当您的PhysicsWorld 被锁定时,它会崩溃。您应该使用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());
    

    【讨论】:

      猜你喜欢
      • 2015-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-12
      • 2016-03-16
      • 1970-01-01
      相关资源
      最近更新 更多