Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  BufferStrategy and flickering  (Read 2194 times)
0 Members and 1 Guest are viewing this topic.
Offline mill

Junior Member




popcorn freak


« Posted 2003-03-16 20:26:08 »

I searched the forums and found nothing.

I did double buffering manually the old way so I decided to incorporate BufferStrategy in my game.

All I changed in my rendering loop is that I use strategy.getDrawGraphics() to get a Graphics object to draw on and then strategy.show() to flip.

However, this results in heavy flickering. It seams like it draws graphics only on every other Graphocs object.

Is this a commong problem meaning I've missed something fundamental?

Basically I use this approach: First I have some menus and stuff (I use Swing for buttons here) and then when playing I use no Swing stuff at all. I pass the Graphics object along to my dufferent objects to draw on (track, cars, etc).

Any idea? Is it the Swing stuff that messes everything up or is something else wrong? I can describe my rendering loop in detail if needed.

Offline bedelf

Junior Member




Are you suggesting coconuts migrate?


« Reply #1 - Posted 2003-03-17 00:29:10 »

well, to start, how many buffers are you using? createBufferStrategy(1) will still flicker
Offline TSwitch

Junior Newbie




Java games rock!


« Reply #2 - Posted 2003-03-17 02:04:03 »

Quote
well, to start, how many buffers are you using? createBufferStrategy(1) will still flicker


In my "adventures" with BufferStrategy and it's ilk, I've read through the code for both Component implementations of BufferStrategy and at least FlipBufferStrategy won't let you use less than 2. I'm not sure about Blit... I guess he can't be using 1 buffer if he's using flipping.

Maybe, if he's using active rendering, his paint method is still being called and that could have something to do with it. Probably not.

We need more info, is what.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline mill

Junior Member




popcorn freak


« Reply #3 - Posted 2003-03-17 07:46:30 »

I found the second constructor so now things are working somewhat better. It's still not perfect -- some stuff do not get draw initially -- it just behaves oddly.

before I used createBufferStrategy(2) but now I use this instead:
BufferCapabilities cap = new BufferCapabilities(new ImageCapabilities(true), new ImageCapabilities(true), BufferCapabilities.FlipContents.COPIED);
createBufferStrategy(2, cap);

anyway, have anyone of you tried to draw Swing components (eg JButtons) and used BufferedStrategy at the same time?

about passive and active rendering.. I've set  setIgnoreRepaint(true) and I'm calling my draw method from my game loop manually.

Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #4 - Posted 2003-03-17 16:57:53 »

sigh,
if a method doesn't appear to be working as expected,
don't just try to work around it,
find out *why* its not working!
it'll only cause you problems later on otherwise.

createBufferStrategy(2) should work just fine.
(java will use the optimum strategy for your current display mode.)

it sounds to me like u are assuming the contents of the buffer after a page flip is in a known state.
By default (when using createBufferStrategy(2)) the buffer contents after a page flip are Undefined.
(which would result in your 'flicker')

post your main class, it won't be hard to find the problem.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline mill

Junior Member




popcorn freak


« Reply #5 - Posted 2003-03-17 17:10:30 »

umm I guess my rendering loops should be enough

first I create the BS in the constructor:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
BufferCapabilities cap = new BufferCapabilities(new ImageCapabilities(true), new ImageCapabilities(true), BufferCapabilities.FlipContents.COPIED);
try {
parent.createBufferStrategy(2, cap);
}
catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
strategy = parent.getBufferStrategy();
dBuff = strategy.getDrawGraphics();


and my game loop then looks like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
while (running) {
            calcDeltaTime();
           

            switch (gameState) {
                case RACING :
                    raceManager.performGameTick(dt);
                    render();
                    if (raceManager.raceOver()) {
                        upgradeScreen.addComponents(this);
                        gradeScreen.paintdBuff);
                        gameState = UPGRADESCREEN;
                        setDefaultCursor();
                    }
                    break;
            }

            try {
                synchronized (timer) {
                    timer.wait();
                }
            }
            catch (InterruptedException iE) {}
        }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
public void render() {
        if (!strategy.contentsLost()) {
            dBuff = strategy.getDrawGraphics();

            //panelGfx = g;

            switch (gameState) {
       
                case RACING :
                    raceManager.updateGfx(dBuff);
                    break;
            }

            try {
                strategy.show();
            }
            catch (IllegalStateException e) {
                return;
            }
           
            dBuff.dispose();

            calcFPS();
        }


(btw, how to get the tabs/indentions to display properly?)

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.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (25 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

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

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

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

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

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

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

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
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!