• 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.

Temer

[java] java graphics

9 posts in this topic

I wrote a program to display squares on the screen but when i minimize the window or move a portion off of the screen the squares disappear. that is if i minimize then all the squares disappear and if i move a portion off then the portion of the squares that went off disappears. how do i stop this. here is the src import java.awt.*; import java.applet.*; public class DrawSquare extends Applet { int width = 50, height = 50; int winX=20; int x=winX , y=0; int xdiff = 80, ydiff = 70; public void paint(Graphics g) { g.setColor(Color.blue); // g.fillRect(0,0,200,200); for(int index=0; index <=6; index++) { for(int i=0; i < index; i++) { g.fillRect(x, y, width, height); x+=xdiff; } x=winX; y+=ydiff; } g.setColor(Color.blue); } }
0

Share this post


Link to post
Share on other sites
I''m not sure if this is the best way, but this clears it up, and it shows how to do double buffering (something you will need to know later if you are planning on working on Java games)...

>> START OF CODE

import java.awt.*;
import java.applet.*;

public class DrawSquare extends Applet
{
int width, height, winX;
int x,y, xdiff, ydiff;

Image backbuffer;
Graphics bbg;

public void init() {
width = 50;
height = 50;
winX = 20;
x = winX;
y = 0;
xdiff = 80;
ydiff = 70;
}


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

if (backbuffer == null) {
backbuffer = createImage(this.getSize().width, this.getSize().height);
bbg=backbuffer.getGraphics();
}
bbg.setColor(Color.blue);

for(int index=0; index <=6; index++)
{
for(int i=0; i < index; i++)
{
bbg.fillRect(x, y, width, height);
x+=xdiff;
}
x=winX;
y+=ydiff;

}
bbg.setColor(Color.blue);
g.drawImage(backbuffer, 0, 0, this);
}
}

<< END OF CODE

If there is anything you don''t get about this, please email me at NTPruett@aol.com

Thanks,
Nate
0

Share this post


Link to post
Share on other sites
Hello,

The way to fix this is to use double buffering. Here is how with your code:

    

import java.awt.*;
import java.applet.*;


public class DrawSquare extends Applet {

int width = 50, height = 50;
int winX=20;
int x=winX , y=0;
int xdiff = 80, ydiff = 70;

Image buffer;
Graphics offScreen;

public void init() {
buffer = createImage(getSize().width,getSize().height);
offScreen = buffer.getGraphics();
}


public void paint(Graphics g){
offScreen.setColor(Color.blue);
offScreen.fillRect(0,0,200,200);
for(int index=0; index <=6; index++){
for(int i=0; i < index; i++){
offScreen.fillRect(x, y, width, height);
x+=xdiff;
}
x=winX;
y+=ydiff;
}
offScreen.setColor(Color.blue);
g.drawImage(buffer,0,0,this);
}
}


Hoped this helped.
JP.

=============================
a wise man once said....
=============================
www.thejpsystem.com
0

Share this post


Link to post
Share on other sites
why is there no double buffering in the Simple Graph applet demo that comes with jdk1.3 but there is no problem with that program? Also what is the best program to type java programs in cause i get tired of pressing space and backspace to format code properly in wordpad. is there a way to set up wordpad to work better? by the way thanks for the help though!
0

Share this post


Link to post
Share on other sites
I have nothing to compare it to but Code Warrior Discovery Programming is pretty nice. $50 for java, C++, and C. I got it at Outpost.com and it came the next day.
0

Share this post


Link to post
Share on other sites
That''s weird... I think I found out the answer to your question about how the Simple Graph applet works without double-buffering. When I first looked at it I thought that it was just the simple fact that it uses drawLine() because when I changed the fillRect() in your code to drawLine() it didn''t disappear when I minimized the appletviewer window. That was weird thing #1... that drawLine() doesn''t disappear but fillRect() does... I still thought, "Yeah, that''s great and all... the lines don''t disappear... but what if I positively, absolutely, definitely want to draw a filled rectangle... Hmmm... I could draw lots of lines next to each other... Nahhhh!" Then I noticed weird thing #2... that the Simple Graph applet doesn''t use *any* global variables to generate the lines! Every variable was local to paint, or was sent into it via a the f() method that is defined in Simple Graph... So try this: move all your variable declaration (simple cut and paste) out of the top of the DrawSquare class and put it at the top of the paint() method... Compile and... Voila! The squares stay on the screen! I''m not sure why this works... but if anyone knows please post!

Thanks,
Nate
0

Share this post


Link to post
Share on other sites
Thanks, you''re right it did work. But why does it?? Please someone let us know!

Temer
0

Share this post


Link to post
Share on other sites
Try putting
System.out.println("x = " + x + " y = " + y);
at the end of your paint() method...after the second g.setColor() will do.

You will see that y is not being reset to 0 because you left it a class variable. Basically, the second time paint is called, it starts drawing at 20, 490 which is outside of your appletviewer window. Just put y=0 at the beginning of your paint() method and it should work fine.

System.out.println() is your friend...just take them out when you are done.
0

Share this post


Link to post
Share on other sites
Just in response to the question about an editor, I use EditPlus, which does automatic indenting, keyword highlighting etc. Here is the link. There are a huge range of text editors like this to choose from that normally are free or have a shareware license (Ultraedit is another that comes to mind).

- Daniel
VG Games
0

Share this post


Link to post
Share on other sites