2
\$\begingroup\$

enter image description here

I use a various of MapBodyBuilder in my Libgdx project. I created a body from map.tmx via my MapBodyBuilder and in my SpriteBuilder buildSprite method i created its sprite:

sprite = new Sprite(atlas.findRegion("elementWood0532"));
sprite.setSize(sprite.getWidth() / B2D.PPM, sprite.getHeight() / B2D.PPM);
sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);

and in SpriteBuilder render method I draw it like this:

Vector2 pos = body.getPosition();
sprite.setPosition(pos.x - sprite.getWidth() / 2, pos.y - sprite.getHeight() / 2);
sprite.setRotation((float) Math.toDegrees(body.getAngle()));

//sprites drawing on bodys
game.batcher.enableBlending();
game.batcher.begin();
game.batcher.draw(sprite,
sprite.getX(), sprite.getY(),
sprite.getOriginX(), sprite.getOriginY(),
sprite.getWidth(), sprite.getHeight(),
sprite.getScaleX(), sprite.getScaleY(),
sprite.getRotation());
game.batcher.end();

but it didn't draw on the body. please help.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.