Archived

This topic is now archived and is closed to further replies.

Kanzetsu

[java] Rendering

Recommended Posts

Kanzetsu    122
I''m curious on how you guys/gals do 2D rendering in applets (JDK1.1). All my graphics objects (sprites, tiles) are of class Image, and I use drawImage to draw them onto my backbuffer (an Image). Then I''m using something like drawImage(backBufferImage, 0, 0, null) to draw the buffer itself onto the view Component. Problem is, this turns to be really slow once I try fill the screen with tiles etc. I know it can be done faster, I had a look over att www.ninjagames.com, their Rollerboy games are amazingly fast. Are you using some different technique (pixel arrays, Rasters etc)? Please tell! // Kanzetsu

Share this post


Link to post
Share on other sites
Kanzetsu    122
Hmm, I haven't measured FPS. I was about to post some pseudo-code here when I discovered that I had actually did no calculation to the delay-value, meaning that I actually added a constant delay... *big* duh!

// Kanzetsu

Edited by - Kanzetsu on December 9, 2001 5:21:03 PM

Share this post


Link to post
Share on other sites
Chaoslab    116
You be surprised at how fast (& slow) drawImage is.... After a certain amount of draws it is actually faster to implement your own blitting routines.

This can be done via an integer array, color formats as follows 0xAARRGGBB

You then create And image source with then array as memory image source (See image source and image in the java docs for more detail).

I also suggest setting the setAnimated to true and using newPixels() method to update the image.

Another trick for speed is to used a 24bit color model with no masking as the image construction is about %30 faster for a 24 bit image (the int color layout is then 0x00rrggbb).

The last hint I have for speed is that using paint is slow as it runs concurrently to the main running thread an inside applets it is possible to just null its execution,

public paint(Graphics g){}
public update(Graphics g){}

And in the init method get the default graphics like this

private Graphics gm;

public init()
{
gm = this.getGraphics()
}

and you can now use gm.drawImage(blah....) to update the applet in a none concurrent fashion to paint which is much faster.

NOTE: all of this is for real time graphics based stuff....

Finally another cool thing I have also seen but not done is to implement an image consumer which is faster still (though not much!).

:-)

Share this post


Link to post
Share on other sites