Reputation: 13
I am currently creating a game based on a platform that tilts side to side and there is a ball on that platform. For this ball I applied dynamic body physics and got it to work great, but when I try updating the ball's sprite rotation based on the ball's body angle the sprite will not rotate.
My code is below.
public static void update(float delta) {
delta *= 0.7;
world.step(delta, 10, 4);
//Angular Impulse is here to test if ball sprite is rotating
ballBody.applyAngularImpulse(40, true);
AssetManager.ballSprite.setRotation(ballBody.getAngle());
AssetManager.ballSprite.setPosition(ballBody.getPosition().x,
ballBody.getPosition().y);
}
}
Upvotes: 0
Views: 442
Reputation: 13
Whenever you want to rotate a sprite in libgdx when rendering it you must do:
sprite.draw(spritebatch);
but I made the mistake of trying to render it how I would render anything else:
spritebatch.draw(sprite);
Upvotes: 1