Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 2D / Problems with double buffering on: 2003-04-25 11:06:58
Hi all. I am having troubles double buffering my images. I hope that you can help me and tell me what I'm doing worng.

I have my paint method in my Actor class (base class of all showables) like this:

   [source]  
public void paint( Graphics g )
{
     if( img == null )
           throw new RuntimeException("Calling Paint and image not Created!!!");

     if( buffer == null ) {
           buffer = Util.getBuffer(img);
           //buffer = img;
           
     }
     g.drawImage(buffer,tile.x,tile.y,TILE_SIZE,TILE_SIZE,null);
}
 

And that Util.getBuffer is a static method that allows me to have secevral objects sharing the same image(BufferedImage ins this case). I have it like this:

     
public static Image getBuffer( Image img )
{
     if( allBuffers.containsKey(new Integer(img.hashCode())) )
           return (BufferedImage)allBuffers.get(new Integer(img.hashCode()));
           
     BufferedImage backbuffer = new BufferedImage(Actor.TILE_SIZE, Actor.TILE_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
     Graphics backbuffergc = backbuffer.getGraphics();
     backbuffergc.drawImage(img,0,0,Actor.TILE_SIZE,Actor.TILE_SIZE,null);
     
     allBuffers.put(new Integer(img.hashCode()),backbuffer);
     
     return backbuffer;
}
 [/source]

Well, like this, the Window is blank, no image is shown. Why?
I am using 45x45 png's in MDK 9.1!

Tkz for any help.

[]
2  Java Game APIs & Engines / Java 2D / Re: Problems with BufferStrategy on: 2003-04-21 21:48:30
yep... itś on linux,

So, how do I do this so that it works ok on linux and win?
3  Java Game APIs & Engines / Java 2D / Re: Problems with BufferStrategy on: 2003-04-20 13:53:25
Humz... they are very simply images, I do not even know if they have an alpha chanel (how can I know that?). I tried with jpg format and itś the same.

Whats your advice? I tried to save again the images (using gimp), and there were no option about alpha chanel.
4  Java Game APIs & Engines / Java 2D / Re: Problems with BufferStrategy on: 2003-04-20 11:36:57
I simply paint an Image:

1  
2  
3  
4  
5  
6  
public void paint( Graphics g )
      {
            if( img == null )
                  throw new RuntimeException("Calling Paint and image not Created!!!");
            g.drawImage(img,tile.x,tile.y,TILE_SIZE,TILE_SIZE,null);
      }


And image is loaded like this:

1  
2  
3  
4  
5  
6  
7  
8  
      public static Image getImage( String fileName )
      {
            File file = new File(fileName);
            if( !file.exists() ) {
                  reportFatalError("Image not found: /" + file.getAbsolutePath() );
            }
            return toolkit.createImage(fileName);
      }


EDIT: Oh, and the images are 45x45 png's.
5  Java Game APIs & Engines / Java 2D / Problems with BufferStrategy on: 2003-04-20 11:10:08
I am having problems with the bufferstrategy, and I do not know why. The code compiles and works, mas the performence it's much wort than if i do not user buferstrategy. I am gonna pass part of the code, in hope somo of you guys find a mistake. Tankz.

Here I try to get a good GC

1  
2  
3  
4  
5  
6  
7  
8  
/******* init code *****/
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();

Arena a = new Arena(gc);

(...)


Arena is a Component that draws all my map and actors. It extends canvas and it's in the paint method that she paint's all the stuff. In Arena ctor, I call super(gc);
On the other hand I have a thread that sleeps for a while and then calls repaint(from Agenda).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
/***************** where i use buffering ******/
public void paint( Graphics g )
{
      if(firstTime) {
            createBufferStrategy(2);
            bufferStrategy = getBufferStrategy();
      firstTime=false;
      }

      Graphics graphics = bufferStrategy.getDrawGraphics();

      if( bufferStrategy.contentsLost() )
      return;
      try {
            for( int i = 0; i < vTiles; ++i ) {
                  for( int j = 0; j < hTiles; ++j ) {
                        if( g.getClipBounds().intersects(terrain[i][j].getRectangle()) ) {
                              terrain[i][j].paint(graphics);
                        }
                  }
            }
            m.paint(graphics);
      } finally {
            graphics.dispose();
      }

      bufferStrategy.show();
}


What am I doind wrong? Thankz for any help guys.

[]
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

pw (37 views)
2014-07-24 01:59:36

Riven (38 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00

Cero (60 views)
2014-07-16 00:42:17

Riven (57 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!