Note that there are some explanatory texts on larger screens.

plurals
  1. POdrawImage() for .png files doesn't work in Java applet?
    primarykey
    data
    text
    <p>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:</p> <pre><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 } </code></pre> <p>showStartScreen:</p> <pre><code>public void showStartScreen(Graphics g) { Image intro=img.getImg("pacman-intro.png"); g.drawImage(intro, 0, 0, this); } </code></pre> <p>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 <code>drawImage</code>.</p> <p>The same thing occurs when you win or lose the game,it just hangs instead of drawing the graphic it needs to.</p> <p>You can see this <a href="http://tinyurl.com/a3fj2y" rel="nofollow noreferrer">here</a> (you can use arrow keys to control)</p> <p>P.S I am using double buffering here.</p> <p>Any thoughts..?</p> <p>EDIT: Code for ImgHelper class which is used to load the img:</p> <pre><code>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(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload