• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

DiscoStoo

[java] Double buffering in applets

11 posts in this topic

I am a long time veteran to C++, and just learned Java, mainly for the purpose of writing applets. Of course games are my main focus, and ya'' can''t have games without double buffering! (Or some equivalent form of animation) I''ve found many tutorials, but they all say: "Next lesson: Double buffering in applets!", then there are no more lessons. Almost like it''s a conspiracy... Anyway, I just need to know how to draw to an off-screen buffer instead of onscreen, then how to blit that to the screen. Everything else can be figured out with time. ------------------------------------------------------------ He wants a shoehorn, the kind with teeth, because he knows there''s no such thing.
0

Share this post


Link to post
Share on other sites
I haven''t actually programmed in java in a while, but if I remember correctly, drawing to another buffer is really simple. In fact, it''s just like drawing to the onscreen buffer. You know about wrinting your paint function and passing Graphics g to it? Well, all you need to do to create a new buffer is to make another Graphics object.
Graphics g2 = new Graphics();
then, you draw to that just like you would draw to Graphics g in your paint function.
0

Share this post


Link to post
Share on other sites
Check out http://www.binod.com/reference/index.html
for some good books. I know that the first one under java,
Black Art of Game Programming, has double buffer examples.

An easy way to get double buffering is to use a JApplet instead- this is the swing equivalent of Applet and hence is double buffered - but this is only one solution and probably not the best.
0

Share this post


Link to post
Share on other sites
DiscoStoo,

Here's the way to do double-buffering :

At the class level make an image and a graphics object -


private Image buffer;
private Graphics bg;


Then, in the beginning of the paint method do this -


public void paint(Graphics g)
{
if (buffer == null)
{
buffer = createImage(getWidth(), getHeight());
bg = buffer.getGraphics();
}


After which you draw only to the bg graphics context (i.e. bg.drawRect(x1,y1,x2,y2); ). This draws everything to the off-screen buffer. Then at the end of the paint method -


g.drawImage(buffer, 0, 0, this);
}


This draws the offscreen buffer to the actual screen.

As gdalston suggests above, a JApplet does double-buffering automatically, but, unfortunately, will not run in any major web browsers w/o the Java2 plugin installed... (I might be wrong... I have heard rumors that the newest version of Netscape will run Java2 stuff... but have not downloaded it myself.) That's a pretty major drawback! So you've gotta use the old AWT stuff for applet games still... hopefully this will change in the near future...

Hope this helps,
-Nate


Edited by - DJNattyP on January 10, 2001 12:47:22 PM
0

Share this post


Link to post
Share on other sites
Thanks much, it''s easier than I thought. And actually, I''ve seen double-buffered applets run in my browser, and most things I do write will probably be for my own satisfaction and not published anywhere, so it''s OK.

------------------------------------------------------------
He wants a shoehorn, the kind with teeth, because he knows there''s no such thing.
0

Share this post


Link to post
Share on other sites
Ummm... What else can I do to double buffer an applet? That isn't good enough in my case. Here's my very simple applet. In fact, it's so simple that painting to an offscreen buffer only makes the flickering a LOT worse.

The problem potentially lies in how repaint() is called in the drawing area of that applet. Specifically, I have a MouseMotionListener set up that calls repaint() on mouseMoved().

Running in a JApplet or JFrame eliminates the flicker, which I do on local testing. However, the applet form can't take advantage of that, as I'd prefer not force those without it to download the java plugin.

Edited by - c_wraith on January 21, 2001 7:29:42 PM
0

Share this post


Link to post
Share on other sites
Are you sure you are overriding both paint() & update()?

The only time I''ve seen flickering when double-buffering has been inplemented is when one of those hasn''t been overridden.

eg.

public void paint(Graphics g) {
update(g);
}

public void update(Graphics g) {
... do your double-buffer & actual painting in here.
}
0

Share this post


Link to post
Share on other sites
Um, isn''t that backwards? Isn''t update() supposed to call paint(), not the other way around?

Anyway, I''ve tried overriding both update() and paint(), and either way, it just made the flickering worse. I''ll put up some demonstrations later today.
0

Share this post


Link to post
Share on other sites
Ok, I got it sorted out... I needed to override update() in my applet, in addition to in my component.
0

Share this post


Link to post
Share on other sites
If memory serves me correctly, when a component is painted, paint() is sometimes called, but update() is always called. And the default implementation of update() clears the component - which causes the flickering.

Therefore it''s slightly more efficient for paint to call update and for update to do the painting.
0

Share this post


Link to post
Share on other sites
Ignore that last post. I was talking bollocks.

update() is not always called. paint() is usually called when part of a component is uncovered (update is not called in this case apparently)

I still think update is called more often than paint - I seem to recall reading that somewhere - so the efficiency argument is still true.
0

Share this post


Link to post
Share on other sites