Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Question regarding a double buffer example (at javaworld).  (Read 764 times)
0 Members and 1 Guest are viewing this topic.
Offline DonaldEKnuth

Junior Devvie





« Posted 2005-12-08 00:22:59 »

Hi!

I have looked at http://www.javaworld.com/javaworld/jw-03-1996/jw-03-animation-p2.html and its example 7. It is an example demonstrating moving images on top of each other using double buffering as the update method (implemented "by hand", not  using strategy).

Its update method looks like this:

    public void update(Graphics g) {
   Dimension d = size();

   // Create the offscreen graphics context
   if ((offGraphics == null)
    || (d.width != offDimension.width)
    || (d.height != offDimension.height)) {
       offDimension = d;
       offImage = createImage(d.width, d.height);
       offGraphics = offImage.getGraphics();
   }

   // Erase the previous image
   offGraphics.setColor(getBackground());
   offGraphics.fillRect(0, 0, d.width, d.height);
   offGraphics.setColor(Color.black);

   // Paint the frame into the image
   paintFrame(offGraphics);

   // Paint the image onto the screen
   g.drawImage(offImage, 0, 0, null);
    }

The complete applet code with update() within its example context.

I am wondering why the part titled "Create the offscreen graphics context" in that method checks if the offGraphics exists, and if it doesn't creates it. Why didn't they create it in the init() method instead? They also check if the size has changed, can the size of an applet change at run time? (And if they can, can i prevent this so that I don't need to check for creation at each update() call?)


My 4k 2006 Entry: Sokoban4k
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #1 - Posted 2005-12-08 00:32:25 »

They probably put the code there so it would be in one place, since they were checking for size changes anyway.

I think it is possibel to change the size of an applety dynamically, but it is not common.  I don't know what the normal method for doing it would be.  Perhaps some jscript and manipulating the size in the DOM?

Offline DonaldEKnuth

Junior Devvie





« Reply #2 - Posted 2005-12-08 00:52:09 »

Thanks for your reply. I thought that I would use setResizable(false); in the init() method, but it's not available. Still I can set my own applet size from that method using (in my case) setSize(400, 400);. A bit strange, I guess it won't be a problem.

My 4k 2006 Entry: Sokoban4k
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #3 - Posted 2005-12-08 01:19:46 »

I think it is possibel to change the size of an applety dynamically, but it is not common.  I don't know what the normal method for doing it would be.  Perhaps some jscript and manipulating the size in the DOM?

I managed to crash both Netscape and IE when I tried that stunt back in the day. These days I'd just do it in AJAX. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
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 (36 views)
2014-12-15 09:26:44

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

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

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

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

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

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

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

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

toopeicgaming1999 (37 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!