简体   繁体   中英

Is Java AWT suitable for 2d game rendering?

I'm currently porting my 2D game engine to Java. I looked at some of the game libraries pointed at here on stackoverflow. However, the ones I looked at were rather simplistic and didn't even state if they supported things like alpha transparency, so I decided to port my C++ renderer for which I had already written out the logic.

This renderer is a pure software renderer which uses tiling to avoid needless re-rendering. I optimized its scrolling performance by creating an "offscreen buffer" a little larger than my output pane, and blitting this offscreen buffer onto my output on every frame. This way, I could avoid redrawing tiles needlessly just because I scrolled a pixel on the map.

I used Java's AWT to implement it, using a large BufferedImage for the offscreen buffer. The CPU usage is okay(around twice of what I had in C++), but there's an odd problem with continuous scrolling, where every second or so, the renderer will lag out for around 0.2 seconds.

Since there's nothing in my own code that would occur in these periods, and since the spikes disappear if I don't draw my offscreen buffer onto the main view, I can only conclude that Java is doing some internal optimization of its own. However, I'm not sure what it does, nor do I know which of my own optimizations I would have to remove to get rid of the spikes. Also, it might be that java AWT wasn't made with continuous, high FPS scrolling in mind, and that's entirely unusable for this purpose.

Is there some way for me to get rid of these spikes?

问题更适合于: https : //gamedev.stackexchange.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM