java - More elegant approach regarding the camera -


i'm using libgdx draw 2d scene. before drawing this:

batch.setprojectionmatrix(camera.combined); 

as expected, (0,0) coordinates no longer in bottom left of screen, @ middle of screen.

what more elegant solution position whole scene correctly:

1) translate/position camera accordingly show that's on screen.

2) draw while having in mind (0,0) @ middle now, so:

batch.draw(background, -background.getregionwidth()/2, -background.getregionheight()/2); 

note i'm doing parallax scrolling , first option dispositions midground layer objects bit, expected. if there no solution problem, i'm leaning more towards second option.

try keep objects in "world space" , keep translations "world space" screen in "camera" (the "camera" abstraction around matrices defined translate world space screen space). polluting object's locations information screen cause confusion , problems.

specifically, in case, call

camera.translate(width/2, height/2, 0); 

to (0, 0) lower left (if "world space" entirely in positive coordinate space.

for more details, search around stack overflow opengl camera questions this: in 3d graphics, camera or eye space?


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -