libgdx - Sprite not following body / fixture -


im trying make sprites stay on top of there static bodies (actually fixtures) when camera / screen moves. need achieve this?

background: have player (which dynamic, polygonshape, set box), camera follows player moves upwards in screen.

every x amount of meters generate (static) rectangle few meters in front of player. rectangle body im trying draw sprite on top of, problem when draw it, sprite stays static on screen , doesnt stay ontop of body/fixtures.

my game screen follows player so:

box2dcamera.position.y = player.getposition().y + box2dcamera.viewportheight / 2 - (player.bodyheight); box2dcamera.update(); 

im using libgdx-utils lib draw sprite ontop of rectangle follows:

box2dsprite box2dsprite = new box2dsprite(kidsgame.res.gettexture("badlogic")); fixture.setuserdata(box2dsprite);  sb.begin(); box2dsprite.draw(sb, world); sb.end(); 

thanks help

a spritebatch uses matrix4 rendering.
matrix4 should set cameras combined matrix.
camera.combined changed, when camera moves, should update spritebatchs projectionmatrix calling spritebatch#setprojectionmatrix(camera.combined) inside render(delta).


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -