Pls helpme implement canvas and BufferStrategy on my old 'self made' buffer

Hai all!
As suggested by me cardan2 here: Re: AWT - how to remove (make transparent) one part of an Image
I tried to implement the Web and BufferStrategy in my project.

My old method of buffer selfmade was as follows (note: the explanation is shortened):
-J' use to extend a framework
-J' I create a BufferedImage with that
Image buffer = this.getGraphicsConfiguration().createCompatibleImage(buff_xo, buff_yo);
-J' made a class to manage the buffer (BufferManager)
BufferManager buffMan = new BufferManager(buffer);
- Then I start a regular thread with a class that extends TimerTask, which is practicable (CoreThread)
ScheduledExecutorService core = Executors.newScheduledThreadPool(1);
core.scheduleAtFixedRate(new CoreThread(buffMan), 5, 16, TimeUnit.MILLISECONDS);
-I overloaded directly image update() paint (g) methods and frameworks write "buffer" on the graph of the image
@Override
public void paint(Graphics graph) {
     // Drawing everything from the buffer, and removing flicker effect
     graph.drawImage(buffer, buff_x, buff_y, null);
}

@Override
public void update(Graphics graph) {
     paint(graph);
}
-at the end of my son, when I need to update my screen, I call the paint (g) of the image method.

And it's practically how my work... as you can see, I'm bored a canvas and a BufferStrategy.

Watching this tutorial http://www.javalobby.org/forums/thread.jspa?threadID=16867
I see that he uses to set up of the canvas (easy, that I can do it) and then get the BufferStrategy with her.
After that, it gets the BufferStrategy graph and use it in the threat are paintings on it.
It removes the graphic and uses the BufferStrategy show() method to paint the buffer and update of the screen image.

My problem on the implementation of BufferStrategy, is that I often use the "buffer" Image everywhere in my code (expecially when I need to make calculations with his size) and not simply its graph.
So to implement the use of BufferStrategy, I should send it anywhere in the BufferStrategy where now to send the Image buffer?
And then should be enough to call the show() method of BufferStrategy instead of patint (g) to the end fo my thread, when necessary to screen update?

Thanks to you all!

Patcha wrote:
But my problem is Graphic2D object contains data about the current size of the traced... t-zone - it?
I do a lot of calculations and there on the size or adjacent buffer of collisions.

No, but the BufferStrategy also does not deal with things; the canvas has dimensions.

I'm pretty lazy in this regard and I tend to have a singleton in this class that can call application components to understand the details of such as dimensions. Class singleton has then access to things such as the frame and the canvas, the rest of the code should not know they exist. All drawing is then made to the GUI of base, which could be the BufferStrategy backbuffer or, for example, that of an image from scratch if I want to make a composition before I blow the final result to the screen.

Some people will condemn me for the use of a Singleton, but I don't like much about it really ;)

Tags: Java

Similar Questions

Maybe you are looking for