My latest game is nearing completion and I’m trying to fine tune the works of it. I had it written for phone/pda sizes in an Applet and I have another guy working on converting my code to J2ME code. So now what I’m doing is making it scale up for play at 800x600 and higher for a PC version, but now I’m hitting some performance problems.
I’m using the GAGETimer to keep my framerate at 50fps and I’ve modified the sleepUntil() to return the number of times it it yielded, which I then print on my screen each frame. When I play the game the low-res way at 300x300 I get 6000-12000 yields every frame, I’m happy with that. When I play the high-res way at 800x600 (with different art to match the resolution) the yields are ALWAYS 0. That tells me I need to do a bit of optimizing
So profiling has revealed where the biggest bottlenecks are. I tried bringing up the biggest one a couple of weeks ago on the Java Gaming Forums at Sun, but I didn’t really get much of a response so hopefully you guys can help me tune this up. So here’s the biggest one, aparantly taking 20% of my processing time each loop. It’s where I draw the background tiles of the game. And that’s when there’s like 15 other ships firing their weapons at me on the screen. Without that it’s over 35%
for (int i = bgStartX-Constants.SYSTEM_TILE_WIDTH; i < Constants.GAME_WIDTH; i += Constants.SYSTEM_TILE_WIDTH)
for (int j = bgStartY-Constants.SYSTEM_TILE_HEIGHT; j < Constants.GAME_HEIGHT; j += Constants.SYSTEM_TILE_HEIGHT)
g2d.drawImage(back, i, j, null);
bgStartX is a number%Constants.SYSTEM_TILE_WIDTH which goes in so I can set the BufferedImage “back” just far enough behind the screen to start to satisfy the scrolling effect.
back is created with:
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(width, height, Transparency.OPAQUE)
I look forward to any advice I can get. Thanks in advance!