ゲームを実行すると、黒い画面しか表示されず、画像は表示されません。
私はキロボルトゲーム開発ガイドの助けを借りてゲームをプログラミングしています:http ://www.kilobolt.com/day-4-enter-the-robot.html
何が悪かったのか本当に知りたいです。
Player.java
package HideAndSeek;
import java.awt.*;
import java.awt.image.ImageObserver;
public class Player
{
private Image image;
private double velocity;
private int x;
private int y;
public Player(Image image,double velocity,int x,int y)
{
this.image = image;
this.velocity = velocity;
this.x = x;
this.y = y;
}
public void update(Graphics g,ImageObserver io)
{
g.drawImage(image, 0, 0, io);
}
}
Game.java
package HideAndSeek;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Game extends Applet implements Runnable,KeyListener
{
private Image background;
private Graphics graphics;
private java.net.URL base;
private Player player;
@Override
public void init()
{
background = createImage(this.getWidth(), this.getHeight());
graphics = background.getGraphics();
setSize(800, 480);
setBackground(Color.BLACK);
setFocusable(true);
java.awt.Frame frame = (java.awt.Frame) this.getParent().getParent();
frame.setTitle("Hide and Seek");
base = getCodeBase();
addKeyListener(this);
}
@Override
public void start()
{
player = new Player(getImage(base, "data/character.png"),1.0,0,0);
Thread thread = new Thread(this);
thread.start();
}
@Override
public void stop()
{
}
@Override
public void destroy()
{
}
public void update()
{
if (background == null)
{
background = createImage(this.getWidth(), this.getHeight());
graphics = background.getGraphics();
}
graphics.setColor(getBackground());
graphics.fillRect(0, 0, getSize().width, getSize().height);
graphics.setColor(getForeground());
paint();
graphics.drawImage(background, 0, 0, this);
}
public void paint()
{
player.update(graphics,this);
}
@Override
public void run()
{
while(true)
{
update();
repaint();
try
{
Thread.sleep(17);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
@Override
public void keyPressed(KeyEvent arg0)
{
switch (arg0.getKeyCode())
{
case KeyEvent.VK_UP:
System.out.println("You pressed up arrow");
break;
case KeyEvent.VK_DOWN:
System.out.println("You pressed down arrow");
break;
case KeyEvent.VK_LEFT:
System.out.println("You pressed left arrow");
break;
case KeyEvent.VK_RIGHT:
System.out.println("You pressed right arrow");
break;
case KeyEvent.VK_SPACE:
System.out.println("You pressed the space key");
break;
}
}
@Override
public void keyReleased(KeyEvent arg0)
{
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0)
{
// TODO Auto-generated method stub
}
}