How to use Java2D, the fastest ways !

Hello!

I know a ways how to use Java2D, still, i dont know what ways to avoid,
as i want my Applets to be fully playable, also with Nettops.

I would like to use animations and scales and rotates, still this is very slow on Nettops.
What ways there is to avoid this slowness ??

Should i use large number of spirtes instead of Java2D rotating.
Should i skip Java2D.Transparency ?? Maybe a large number pre ready and partly transparent sprites ??
Should i skip Java2D.Scaling ?? Should i drop the use of scaling and build my sprites calculated from screen height for every user ??
Should i use directwriting for bufferedimages ??

What kind of ways there is to make Java Applets work like a flash on Nettops ??

//----

Thanks,

Java2D!

I have made a decision to build my games on a single 512x512 BufferedImage.

I will grap the pixels of a BImg to a int[] and manipulate BImg data[] from code.
I wont be using DrawImage no more than once for every frame, i will try to build a 30 fps games for Nettops.

I will build my own DrawImage class to fill the only BImg’s int data[].

Graphics ->
one BImg for screen 512x512 or maybe a xy ±100px on some games.
I will draw my game objects datas to int[] array.
I build my own graphics class, my own drawImage will use int data [] arrays to fill bimgs int data [] with graphics data.

Reason why i made this decision was that the ATOM330 ION graphics must work atleast 30 fps on every game i develope.
NETTOPS are the reason for using software based code !!

As i have not been very productive on Java games, so i dont have a lot experience on Java2D,
Is this a foolish way to build my on a build PROJECTS ?? It is a bit more work !!

//----

Thanks,

I’m definitely not an expert on Java2D (it seems no matter what I do with it things go very slowly), but I think using a single BufferedImage can be a good way to go if things aren’t changing too much. Then you can just re-render “dirty” squares in your image to save yourself some processor. If you clear out and then redraw everything to a BufferedImage every render, then you might as well just draw right into a Canvas or JPanel.

yeah but a buffered image will stop flickering.

You shouldn’t get flickering unless you’re drawing in full screen mode, but if you’re doing that then you can just use double-buffering and you won’t have any problems.

[quote]You shouldn’t get flickering unless you’re drawing in full screen mode, but if you’re doing that then you can just use double-buffering and you won’t have any problems.
[/quote]
You mean “unless you aren’t drawing in full screen”

full screen -> bufferstrategy -> all easy, no flicker, nice buffers
windowed is a little tricky, you have to write your dbl buffering stuff yourself

I only use Java2D…

Using the int[] approach will kill hardware acceleration. It will be much easier and will most likely run better if you just let java2D handle it.

Using the int[] as you stated should be fine if you only use it sometimes but it will probably lag even a simple test program if you do it every frame.

You can also use buffered Strategy with windowed . I did it in Hellevators, check my signature .
I guess that’s the fastest wat of drawing it , but that won’t speed up you rotations and scaling, if that’s your bottleneck.

My suggestion is : let’s say you have 30 enemies with same image and one main character, and you need to rotate them all . I would just rotate the main character on-the-fly, but for the enemies, I would save the rotated instances in memory . That way you’ll have just 1 rotation per frame (your character) and on the other hand spend memory where would otherwise be too prcessor expensive .

Is this a Windows thing then? I’ve only had problems with flickering when drawing full screen. If I draw right into a JPanel I don’t ever have any issues.

I never knew bufferstrategy works in window mode, I think I read that it does not, because of the way graphic memory is used or whatever

anyway tried it, and it works beautifully. no flicker

but also not vsync but thats only natural… gotta write a frame skipper / slowdown thing anyway

JPanel and other Swing components are automatically double buffered, but AWT components aren’t. It’s one of the benefits of Swing. I believe it’s often recommended to just use JPanel, or an AWT Canvas with a BufferStrategy (to avoid the loading of all the unnecessary Swing PLAF classes).

Ah, that explains it. I do indeed always use JPanel, so I never noticed a flickering.

it should also happen in mac, I think bobear is right.

cause all the flickering is that everything is not being drawn at the same time, so if you empty the scree, you will see a blank screen for a second, and then you will see whatever you draw, then the blank screen again, hence the flickering.

That makes good sense. I just happened to have used things with automatic buffers every time, except for when I implemented fullscreen. :slight_smile: