Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  double buffering woes  (Read 1421 times)
0 Members and 1 Guest are viewing this topic.
Offline CyanPrime
« Posted 2011-08-02 00:04:32 »

Can anyone tell me why this ain't double buffering?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public void paint(Graphics g) {
       
        Graphics2D g2d = (Graphics2D) screen.getGraphics();
       
        g2d.setColor(Color.black);
        g2d.fillRect(0, 0, 640,480);
   
        for(int i = 0; i < stars.length; i++){
                g2d.setColor(new Color(stars[i].r, stars[i].g, stars[i].b));
                g2d.fillRect(stars[i].x, stars[i].y, (int) stars[i].size, (int) stars[i].size);
        }
       
        g.drawImage(screen, 0, 0, null);
    }
Offline Z-Man
« Reply #1 - Posted 2011-08-02 00:32:02 »

It looks like it is... Your drawing to an image, and then drawing that image to the screen. At least that's what it looks like to me. Why are you using paint() instead of paintComponent() though?
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2011-08-02 00:48:32 »

It looks like it is... Your drawing to an image, and then drawing that image to the screen. At least that's what it looks like to me. Why are you using paint() instead of paintComponent() though?
Perhaps he is using Canvas instead of Component.

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2011-08-02 00:52:42 »

Isn't double buffering only applied to Graphics object that you get from the object that you're using to draw?

Offline Z-Man
« Reply #4 - Posted 2011-08-02 01:28:55 »

It looks like it is... Your drawing to an image, and then drawing that image to the screen. At least that's what it looks like to me. Why are you using paint() instead of paintComponent() though?
Perhaps he is using Canvas instead of Component.
True I didn't think about the fact that he could be using AWT, my bad.

Isn't double buffering only applied to Graphics object that you get from the object that you're using to draw?
You mean when you use setDoubleBuffered()? Yea I think it only applies to graphics objects you get from the component, not to images and what not. But that's not what CyanPrime is doing. He is drawing to an image, then drawing that image onto his component. That sounds like double buffering to me.
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #5 - Posted 2011-08-02 01:58:25 »

Did you override update(Graphics g)?

1  
2  
3  
public void update(Graphics g) {
  paint(g);
}

Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #6 - Posted 2011-08-02 22:07:15 »

Did you override update(Graphics g)?

1  
2  
3  
public void update(Graphics g) {
  paint(g);
}

What's the point of that? update(Graphics) already calls paint(Graphics).

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #7 - Posted 2011-08-02 23:35:27 »

Did you override update(Graphics g)?

1  
2  
3  
public void update(Graphics g) {
  paint(g);
}

What's the point of that? update(Graphics) already calls paint(Graphics).
And it also calls other things, which you are avoiding.

See my work:
OTC Software
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #8 - Posted 2011-08-03 01:10:05 »

Did you override update(Graphics g)?

1  
2  
3  
public void update(Graphics g) {
  paint(g);
}

What's the point of that? update(Graphics) already calls paint(Graphics).
And it also calls other things, which you are avoiding.
What other things would update(Graphics) be calling? O_o

Offline BoBear2681

JGO Coder


Medals: 18



« Reply #9 - Posted 2011-08-03 02:30:47 »

Canvas clears itself in update() before calling paint().
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #10 - Posted 2011-08-03 16:43:30 »

Canvas clears itself in update() before calling paint().
Oh yeah! Forgot about that Tongue

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.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (73 views)
2014-09-10 06:39:09

Tekkerue (37 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (44 views)
2014-09-07 01:13:42

Longarmx (27 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!