Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to use Java2D, the fastest ways !  (Read 4310 times)
0 Members and 1 Guest are viewing this topic.
Offline NewOnJava

Junior Devvie




1970 born Java game hobbyer.


« Posted 2009-12-10 07:47:03 »

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,,
Offline NewOnJava

Junior Devvie




1970 born Java game hobbyer.


« Reply #1 - Posted 2009-12-12 12:25:59 »

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,,
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2009-12-12 23:28:55 »

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.

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #3 - Posted 2009-12-13 07:19:20 »

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.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #4 - Posted 2009-12-13 18:47:28 »

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.

See my work:
OTC Software
Offline Cero
« Reply #5 - Posted 2009-12-23 23:38:36 »

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.
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...

Offline zoto

Senior Devvie


Medals: 4



« Reply #6 - Posted 2009-12-24 00:06:40 »

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.
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #7 - Posted 2009-12-24 03:13:49 »

full screen -> bufferstrategy -> all easy, no flicker, nice buffers

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 .

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #8 - Posted 2009-12-27 20:55:43 »

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...
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.

See my work:
OTC Software
Offline Cero
« Reply #9 - Posted 2009-12-28 01:48:10 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline BoBear2681

JGO Coder


Medals: 19



« Reply #10 - Posted 2009-12-28 02:34:10 »

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).
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #11 - Posted 2009-12-28 14:21:28 »

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.

See my work:
OTC Software
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #12 - Posted 2009-12-28 14:44:46 »

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.

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.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #13 - Posted 2009-12-31 21:53:13 »

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. Smiley

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (46 views)
2014-11-29 21:32:03

toopeicgaming1999 (113 views)
2014-11-26 15:22:04

toopeicgaming1999 (100 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!