Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (483)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
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 / Re: Am I double buffering correctly? Do I need to? on: 2012-03-09 07:10:17
I jumped from about 80fps to 170fps after implementing your code. Thats without even changing the double handling of the BufferStrategy and BufferedImage.  Grin
2  Java Game APIs & Engines / Java 2D / Re: Am I double buffering correctly? Do I need to? on: 2012-03-09 04:59:25
Thanks mate I do appreciate the help.
3  Java Game APIs & Engines / Java 2D / Re: Am I double buffering correctly? Do I need to? on: 2012-03-09 00:57:12
Awesome code. Is it still possible to work on a BufferStrategy on a per pixel basis? Suppose that I wanted to blit all the pixels into black and white for a dream sequence.

Its interesting that I got my Rendering loop ideas largely from Notch's Ludum Dare entries. I wonder if he does his 2D game rendering sub-optimally.
4  Java Game APIs & Engines / Java 2D / Am I double buffering correctly? Do I need to? on: 2012-03-08 04:36:41
Hi guys. Thanks in advance for the help.

I'm whipping up a 2D engine for the first time. I've copied my render loop below. What seeking help for here is a better understanding of BufferStrategy and Buffering to an offscreen Image, when they should be employed, and if I'm doing it wrong.

One approach I've read about is reading images into an array of pixels then using a blit method to insert them on a per pixel basis to an offscreen image, then painting the image. I believe I've began preparing for this method below.

Would it be a better idea just to read the image into a BufferedImage and then use the drawImage() method to draw it onto the Graphics of the BufferStrategy? Moreover, when I draw text and lines would I be drawing them onto the offscreenGraphics? or the Graphics of the BufferStrategy?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
    public void render() {
        BufferStrategy bs = getBufferStrategy();
        if (bs == null) {
            createBufferStrategy(3);
            requestFocus();
            return;
        }


        Graphics g = bs.getDrawGraphics();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.translate((getWidth() - GAME_WIDTH * SCALE) / 2, (getHeight() - GAME_HEIGHT * SCALE) / 2);
        g.clipRect(0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE);


        offscreenGraphics.setBackground(Color.WHITE);
        offscreenGraphics.clearRect(0, 0, getWidth(), getHeight());
        offscreenGraphics.setColor(Color.BLACK);
        offscreenGraphics.drawLine(0, 0, 100, 100);

        // Stress test of changing each pixel individually.
       for (int x = 0; x < GAME_HEIGHT; x++) {
            for (int y = 0; y < GAME_WIDTH; y++) {
                pixels[(x * GAME_WIDTH) + y] = 0xFF3333;
            }
        }

        // Testing drawing a line
       offscreenGraphics.draw(new Line2D.Double(5, 5, 500, 500));

        // Testing drawing a string.
       offscreenGraphics.drawString(Integer.toString(framesPerSecond), 100, 100);

        g.drawImage(offscreenImage, 0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE, 0, 0, GAME_WIDTH, GAME_HEIGHT, null);
        g.dispose();
        bs.show();
    }


Other code that I'm using is:

1  
2  
3  
        renderHints.put(RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_QUALITY);
        offscreenGraphics.setRenderingHints(renderHints);
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (15 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
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!