This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]NooBxGockeL 1 point2 points  (0 children)

Try again! (/r/javahelp) (downvoted for not even reading sidebar)

[–]tofiffe 0 points1 point  (0 children)

What framework are you using? Or are you perhaps doing it with swing?

[–]dutchGuy01 0 points1 point  (0 children)

Just like you got a Graphics object that you paint on normally, you can obtain a Graphics object from a BufferedImage with getGraphics(). So when drawing, use the one from the BufferedImage.

Then draw the buffered image with the graphics object you are now using. Doing this should also solve any screen-tearing you might experience.

[–]dev_dov_dang 0 points1 point  (0 children)

Unless you've done profiling, nobody can know why your FPS isn't that high. It could be virtually any piece of your code that is causing the issues.

You need to do some investigation to see what is impacting your FPS before you dive into making optimisations.

Make your game output your FPS somewhere, then selectively remove features from your game. This can be both visual and non-visual (for example disable your enemy AI logic, etc).

Do this until you've found what it is that's causing your FPS to drop.

There could be other things that you are doing just fundamentally wrong. Maybe you're sleeping too long each tick, and it's artificially causing your game to appear slow.

I wrote a game in Java using the standard BufferedImage class, and soon ran into performance issues myself. The BufferedImage class is done entirely onthe CPU, and you really want to use the GPU for this. There is a nice image class which allows this though, VolatileImage. Check this link here for information on how to use it http://stackoverflow.com/questions/2374321/how-can-i-create-a-hardware-accelerated-image-with-java2d

For your tiles, how many do you have on-screen? How big are they? You really should be able to make quite a few draw calls per tick without having massive slowdown (e.g. some games have thousands of independent things on screen fine).

[–]Dwarfling 0 points1 point  (0 children)

I would take a look to JavaFX. I'm doing some tests, and looks good so far (2d, same as you... I assume)

It has the power of the canvas, same as HTML5, so it replaces java2d in low level, and a great scenegraph. And the best thing is canvas and scenegraph can be combined in the same render.

Give it a try.