I will shoe the relevant parts of my code and maybe you can find what I need to do. I have googled and seen things with dubble buffering and stuff, but I don't really get it.
The code here is just a lot of stuff, I have removed a lot of "game logic" and image files so the names are not the same, but you will at least get my method with this code:
public class Game3 extends JPanel implements ActionListener{
ImageIcon flowerIcon = new ImageIcon("img\\Dragon.gif");
Image flower = flowerIcon.getImage();
ImageIcon flowerhitIcon = new ImageIcon("img\\DragonHit.gif");
Image flowerhit = flowerhitIcon.getImage();
ImageIcon flowerfireIcon = new ImageIcon("img\\DragonFire.gif");
Image flowerfire = flowerfireIcon.getImage();
URL music = null;
AudioClip musicSound;
URL pop = null;
AudioClip popSound;
Font font;
Random r;
boolean skott = false;
Nalle nalle = new Nalle();
ArrayList<Bubble> bubblor = new ArrayList<Bubble>();
Timer tim;
Game3(){
try {
wee = new URL("file:img\\wee.wav");
}
catch (MalformedURLException exp) {
}
weeSound = Applet.newAudioClip(wee);
try {
namnam = new URL("file:img\\namnamn.wav");
}
catch (MalformedURLException exp) {
}
namnamSound = Applet.newAudioClip(namnam);
bubbles = Integer.parseInt(textBubbles);
tim = new Timer(20, this);
setFocusable(true);
addKeyListener(k);
musicSound.loop();
tim.start();
}
}
public void checkCollisions(){
blablabla
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
if(Map.redLevel == true){
g2d.drawImage(background, himmelX, himmelY, null);
g2d.drawImage(background2, himmelX2, himmelY2, null);
g2d.drawImage(lava, grassX+80, grassY+355, null);
g2d.drawImage(lava, grassX+680, grassY+130, null);
repaint();
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
blablabla....
}






