Reputation:
I want to make a ball, so far I have rendered as simple texture on my circle and the ball rotates by the texture does not. Here is what I have so far:
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);
And in render I have:
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);
Any ideas how I can make the texture rotate as well? Thanks in advance.
Upvotes: 1
Views: 1315
Reputation: 1149
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);
Upvotes: 1