Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (292)
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 / Last pictures of an animation not persistent on: 2003-04-24 07:13:56
Hi,

I have a problem with my animation. Or to be more precise
when it's finished. I would like to see on the screen the
last image but I simply got the background of the frame.

I have a tile map and each cycle, there is a loop that call
the tiles to draw what is on itself. Here is the method that
do the job:

public void displayImageAt(String imageType, int imageIndex, int x, int y) {
   
   ImageIcon imageIcon;
   Image image;
   int index;
   int width, height;
   
   image = imagesDescriptor.getImageByName(imageType,imageIndex);
   // instead of storing Images, I'd better store ImageIcon
   // to avoid this studip instance creation each time!
   imageIcon = new ImageIcon(image);
   
   width = imagesDescriptor.getElementSize();
   height = imagesDescriptor.getElementSize();
   
   if (jPanel==null) {
       // null for no Layout Manager
       // true for dubbleBuffered
       jPanel = new JPanel(null,true);
       jPanel.setOpaque(false);
       frame.setContentPane(jPanel);
   }
   Dimension dim = jPanel.getSize();
   RepaintManager rm = RepaintManager.currentManager(jPanel);
   Image off = rm.getOffscreenBuffer(jPanel, dim.width, dim.height);
   Graphics og = off.getGraphics();
   Graphics g = jPanel.getGraphics();
   if (og!=null) {
       try {
           imageIcon.paintIcon(jPanel,  og,y*height, x*width);
           g.setClip(y*width,x*height,width, height);
           g.drawImage(off,0,0,jPanel);
       }
       finally {
           og.dispose();
           g.dispose();
       }
   }
   frame.setVisible(true);
   
}

Yes, it's not very clean (creation of ImageIcon each time, but
that's not the problem here, I'll fix it later).
My problem is that when the simulation cycle stops the frame doesn't
keep the last tiles diplayed but the background of the frame.

What should I do to fix that?

The frame is created in the constructor of my class like this:

frame = new JFrame("Environment Display");
frame.addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent e) {

System.exit(0);
   }
});

frame.setBounds(120,120, 450,520);
frame.setVisible(true);

and jPanel is a JPanel attribute of my class.

All propositions accepted. :)

Greetings,

The Ant.
Pages: [1]
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (67 views)
2013-05-17 21:29:12

alaslipknot (76 views)
2013-05-16 21:24:48

gouessej (109 views)
2013-05-16 00:53:38

gouessej (104 views)
2013-05-16 00:17:58

theagentd (115 views)
2013-05-15 15:01:13

theagentd (104 views)
2013-05-15 15:00:54

StreetDoggy (149 views)
2013-05-14 15:56:26

kutucuk (172 views)
2013-05-12 17:10:36

kutucuk (170 views)
2013-05-12 15:36:09

UnluckyDevil (179 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.052 seconds with 21 queries.