tags:

views:

597

answers:

2

I made this pacman game using an applet. When the applet finishes loading, it is meant to display a 'start menu' graphic i made which says 'Double click to start the game', etc. The graphic would take up the whole 400x400 applet. Here's the code:

public void paint(Graphics g)
{
 if (! isRunning)
 {
  switch (result)
  {
   case 0:
    showStartScreen(g);
   break;

   case 1:
    showWonScreen(g);
   break;

   case -1:
    showLostScreen(g);
   break;
  }
  return;
 }
      //Code for rendering other stuff if game is here
}

showStartScreen:

public void showStartScreen(Graphics g)
{
 Image intro=img.getImg("pacman-intro.png");
 g.drawImage(intro, 0, 0, this);

}

This works fine when I run this locally on Eclipse, but in the web browser, when the applet is loaded I just see a blank box where the java's loading animation previously was. Surprisingly, if I double click randomly where the applet is meant to be, the game starts and works as normal. So this makes me think that the problem is just with drawing .png files using drawImage.

The same thing occurs when you win or lose the game,it just hangs instead of drawing the graphic it needs to.

You can see this here (you can use arrow keys to control)

P.S I am using double buffering here.

Any thoughts..?

EDIT: Code for ImgHelper class which is used to load the img:

import java.awt.Image;
import java.net.URL;

import javax.swing.ImageIcon;

public class ImgHelper
{
    public Image getImg(String file)
    {
            //Engine is the name of the base applet class
     URL url=Engine.class.getClassLoader().getResource("assets/" + file);
     return new ImageIcon(url).getImage();

    }


}
+1  A: 

Are the pngs in the right directory? Is "." in the path env-variable on the server?

Try "./pacman-intro.png" i.e.

Peter
yes, paths aee correct, i've double checked. The imgHelper.getImg method adds the / before the image
Click Upvote
+2  A: 

Ah, I checked the contents of your jar file.

Replace "pacman-intro.png" with "pacman-intro.PNG". It's case-sensitive.

amarillion