Better way to move the map according to player position?

Hello,

I’m developing a 2D game with tiled-based maps. So, when my player moves any point after/before screenWidth / 2 or screenHeight / 2, it’ll .glTranslate the map and everything drawn on it. To calculate when it should translate or not, untranslate or not, and how much translate, I’m not using anything like matrixes: I’m just using pure math code.

My question is: is there a way to do it better? This way, right now, isn’t affecting performance or anything related, but I’m just wondering if I could get the same result using transformation or projection matrixes? (Since I don’t know how those works.)

Thanks.

It really depends on what method you are using to render.

If you are using OpenGL (LWJGL, JOGL, LibGDX), then most certainly using matrices is a very good idea. Translating with OpenGL is as simple as calling glTranslate() (and you should probably set the matrix mode to the modelview beforehand with glMatrixMode(GL_MODELVIEW) ).

If you are using just Java2D, then I’m not an expert. But I expect that the way you are doing it would be just as good as any other.

If you would like to know about matrix maths then I recommend this website. Taught me everything I know, at least it did when I was starting out.http://www.wildbunny.co.uk/blog/vector-maths-a-primer-for-games-programmers/