简体   繁体   中英

LibGDX Sprite Not Rotating With Both “Rotate” and “setRotation”

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);

    }

}

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM