I’ve been at this for awhile and I know how to do most things. I had to take Java for my comp. sci. degree at Penn State where I will be a junior starting next semester. I used the code of a well known youtuber called the Cherno as a base. He handled the graphics with the BufferedImage class and pixel arrays. I tried that but with my bigger window size and bigger tiles I was getting only a few frames per second at maximum.
So I tried instead to just draw the sprites on the screen without converting them to pixels first and getting it all together in one big pixel array. That also gave terrible performance but because of drawing all the tiles - not because of all the copying of pixel arrays like for the Cherno’s method. Btw I have a hot gaming PC I’m doing all this on and I still get this really low fps issue.
I enabled java 2d in Eclipse (-Dsun.java2d.opengl=true) and I used the graphics 2D methods for drawing but it didn’t help performance. I am trying to do things this way because my understanding is that, unlike with the pixel arrays, I can make use of the graphics card or chip to speed up the performance of image drawing. So, my first question is how to get the opengl hardware acceleration involved so I can draw all this on the screen and still have a reasonable fps.
My second question is how to maintain layers when I draw to the screen and keep the screen from flickering. I understand how the pixel array method did this (the method I’d prefer to use but it lacks the potential for hardware acceleration), but I’m not sure how to do it when I am repeatedly calling the drawImage method in my rendering method. Is this what BufferStrategy is supposed to do? I don’t have flickering, I just anticipate it when I get my tiles to display properly behind the player character.
So I have two things I’m asking about, basically. How do I or can I enable hardware acceleration for drawing and do I use buffer strategy or something else to draw properly in the game loop.