Libgdx和Box2d与CircleSgape一起旋转纹理

时间:2013-07-17 08:41:01

标签: box2d libgdx

我想制作一个球,到目前为止,我已经在我的圆圈上渲染了简单的纹理,并且球体旋转的纹理没有。以下是我到目前为止的情况:

    bodyDef = new BodyDef();  
    bodyDef.type = BodyType.DynamicBody;  
    bodyDef.position.set(new Vector2(240,320));  
    body = world.createBody(bodyDef);  
    CircleShape dynamicCircle = new CircleShape();  
    dynamicCircle.setRadius(15f);  
    FixtureDef fixtureDef = new FixtureDef();  
    fixtureDef.shape = dynamicCircle;  
    fixtureDef.density = 1.0f;  
    fixtureDef.friction = 0.5f;  
    fixtureDef.restitution = 0.8f;  
    body.createFixture(fixtureDef); 
    body.applyTorque(100000000);

在渲染中我有:

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    batch.draw(texture, body.getPosition().x,body.getPosition().y);
    batch.end();
    world.step(BOX_STEP, BOX_VELOCITY_ITERATIONS, BOX_POSITION_ITERATIONS);  

任何想法如何让纹理旋转?提前谢谢。

1 个答案:

答案 0 :(得分:1)

 batch.draw(texture, body.getPosition().x, body.getPosition().y, width/2, height/2, width, height, /*scaleX*/1, /*scaleY*/1, /*rotation*/ body.getAngle() * MathUtils.radToDegree, srcX, srcY, srcWidth, srcHeight, /*flipX*/false, /*flipY*/false);