Hi, i have a problem with the Basics of Game Programming.
I have programmed the logic of my game, and was now about to
try to implement the graphical representation.
Since its a strategy game, i there is not much of animations,
only some kind of Solarsystem(with different planets)
within wich an little ship icon can be moved and etc.
I have collected Gifs (about 90x90 Planets, suns 100x100, and background
800x600)
and wanted to draw them on a JPanel. And maybe, after i would
have achieved this, make some kind of orbits, animations(rotation).
But i cant even draw one image , without an overflow.
here my Code:
public class SolarSystemView extends JPanel {
int width = 800, height = 600;
private SolarSystem system;
private BufferedImage planetD;
private BufferedImage planetH;
private BufferedImage planetJ;
private BufferedImage planetK;
private BufferedImage planetL;
private BufferedImage planetM;
private BufferedImage planetN;
private BufferedImage planetT;
private BufferedImage planetY;
private BufferedImage sunRedDwarf;
private BufferedImage sunYellowDwarf;
private BufferedImage sunRedGiant;
private BufferedImage background;
private BufferedImage offImage;
private Graphics dbg;
public SolarSystemView() {
try {
this.setPreferredSize(new Dimension(800,600));
background = ImageIO.read(SolarSystem.class.getResource("/Icons/Planets/background.gif"));
sunRedGiant = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/RedGiant.gif"));
} catch (IOException e) {
System.err.println("IOException thrown 45");
}
}
public SolarSystemView(SolarSystem system) {
try {
planetD = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/D.gif"));
planetH = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/H.gif"));
planetJ = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/J.gif"));
planetK = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/K.gif"));
planetL = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/L.gif"));
planetM = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/M.gif"));
planetN = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/N.gif"));
planetT = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/T.gif"));
planetY = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/Y.gif"));
sunRedDwarf = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/RedDwarf.gif"));
sunYellowDwarf = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/YellowDwarf.gif"));
sunRedGiant = ImageIO.read(SolarSystemView.class.getResource("/Icons/Planets/RedGiant.gif"));
background = ImageIO.read(SolarSystem.class.getResource("/Icons/Planets/background.gif"));
GraphicsConfiguration gfxConf = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
offImage = gfxConf.createCompatibleImage(width, height);
} catch (IOException e) {
System.err.println("IOException thrown #line");
}
this.system = system;
}
public void paint(Graphics g) {
if (offImage == null) {
int width = 800, height = 600;
offImage = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
dbg = offImage.getGraphics();
}
dbg.setColor(Color.BLACK);
dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
dbg.drawImage(sunRedGiant, width / 2 - 100, height / 2 - 100, this);
paint(dbg);
g.drawImage(offImage, 0, 0, this);
}
}
I used the empty constructor.
The planets are not used yet…lateron i would paint a specified sun, up to 10 planets…-.-
plz help XD
edit: ah, and excuse my poor english -.-
i really cant imagine why i put that call there…sry to have bothered you ^^