BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-22-2009, 06:37 AM   #1
cristisor
Knows Where the Search Button Is
 
Join Date: Jul 2009
Model: 8800
PIN: N/A
Carrier: Vodafone
Posts: 15
Default How to implement double buffering?

Please Login to Remove!

Hi,
I'm porting a game from MIDP to the BB API but the Screen classes' double buffering doesn't work like in GameCanvas. I can't do all the painting in the paint(g) method so I created an auxiliary buffer and in paint I draw the buffer, but I still get the flickerings:

Code:
theBuffer = new Bitmap(screenWidth, screenHeight);
theGraphics = Graphics.create(theBuffer);

protected void paint(Graphics graphics) {
    super.paint(graphics);
    graphics.pushContext(new XYRect(0, 0, screenWidth, screenHeight), 0, 0);
    graphics.drawBitmap(0, 0, theBuffer.getWidth(), theBuffer.getHeight(), theBuffer, 0, 0);
    graphics.popContext();
}
I draw everything in "theGraphics".
Offline  
Old 09-22-2009, 07:37 PM   #2
ptys
Knows Where the Search Button Is
 
Join Date: Jul 2008
Model: none
PIN: N/A
Carrier: none
Posts: 26
Default

Have you tried the midp version of this game on BB? If you haven't, then it may be just that hardware you're on, and not the lack of buffering. BB's cpu's are much slower than the competition's and it's much harder to get comparable frame rates.

Try avoiding full screen repaints if possible. Instead of buffering the whole screen, try buffering sections of the screen and paint only what's changed, etc. Profile your code.

Quote:
Originally Posted by cristisor View Post
Hi,
I'm porting a game from MIDP to the BB API but the Screen classes' double buffering doesn't work like in GameCanvas. I can't do all the painting in the paint(g) method so I created an auxiliary buffer and in paint I draw the buffer, but I still get the flickerings:

Code:
theBuffer = new Bitmap(screenWidth, screenHeight);
theGraphics = Graphics.create(theBuffer);

protected void paint(Graphics graphics) {
    super.paint(graphics);
    graphics.pushContext(new XYRect(0, 0, screenWidth, screenHeight), 0, 0);
    graphics.drawBitmap(0, 0, theBuffer.getWidth(), theBuffer.getHeight(), theBuffer, 0, 0);
    graphics.popContext();
}
I draw everything in "theGraphics".
Offline  
Old 09-23-2009, 02:27 AM   #3
cristisor
Knows Where the Search Button Is
 
Join Date: Jul 2009
Model: 8800
PIN: N/A
Carrier: Vodafone
Posts: 15
Default

The MIDP version is double buffered. After some research I found a way to do the double buffering: I make a secondary buffer, theBuffer, upon which I call the drawing method inside a "invokeAndWait()" and invalidate after this. In the paint method I paint only the buffer on the screen, like in the paint method posted on the first post.

Code:
UiApplication.getUiApplication().invokeAndWait(
        new Runnable() {
            public void run() {
                draw();
                invalidate();
            }
        }
);
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


GE Voltage Stabilizer 10 KVA Transformer Pri 175-235/190-260/380-520 Sec 120/240 picture

GE Voltage Stabilizer 10 KVA Transformer Pri 175-235/190-260/380-520 Sec 120/240

$648.00



Phoenix Contact Voltage Distribution Block Part No. 2315269 picture

Phoenix Contact Voltage Distribution Block Part No. 2315269

$30.00



(5) MicroChip MCP1700-3302E/TO Fixed 3.3V LDO Voltage Regulators - USA Shipping picture

(5) MicroChip MCP1700-3302E/TO Fixed 3.3V LDO Voltage Regulators - USA Shipping

$6.95



USB Killer V3 White U Disk Miniatur Power Module High Voltage Pulse Generator picture

USB Killer V3 White U Disk Miniatur Power Module High Voltage Pulse Generator

$14.25



Renogy 500A Battery Monitor High and Low Voltage Programmable Alarm 500A Shunt picture

Renogy 500A Battery Monitor High and Low Voltage Programmable Alarm 500A Shunt

$70.99



USB Type-C Meter Tester Digital Multimeter Current Voltage Power Detector +Cable picture

USB Type-C Meter Tester Digital Multimeter Current Voltage Power Detector +Cable

$19.98







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.