Estava fazendo esse tutorial aqui pra criar um alien invaders em java: http://www.cokeandcode.com/node/6
Fui fazer algumas modificações no código e tive alguns problemas...
Primeiro, tentei inserir um background de várias maneiras mas não funciona, o eclipse também não acusa erro.Meu código é o seguinte: Carregando 'Img1' na classe principal:private Image Img1 = Toolkit.getDefaultToolkit().getImage("http://img40.imageshack.us/img40/6543/51452588.gif");
Tentando chamar ela no loop:
public void gameLoop() {
long lastLoopTime = System.currentTimeMillis();
while (gameRunning) {
long delta = System.currentTimeMillis() - lastLoopTime;
lastLoopTime = System.currentTimeMillis();
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0,0,800,600);
//não funcionou
g.drawImage(Img1, 800, 600, null);
A segunda dúvida, como quero rodar ele numa XML, preciso carregar os Sprites de URLs da web, segundo o autor do tutorial a classe SpriteStore já estaria pronta pra isso, porém quando tento o eclipse da esse erro:
[color=red]Can't find ref: http://img101.imageshack.us/img101/9447/alienvx.gif[/color]
public Sprite getSprite(String ref) {
if (sprites.get(ref) != null) {
return (Sprite) sprites.get(ref);
}
BufferedImage sourceImage = null;
try {
URL url = this.getClass().getClassLoader().getResource(ref);
if (url == null) {
fail("Can't find ref: "+ref);
}
sourceImage = ImageIO.read(url);
} catch (IOException e) {
fail("Failed to load: "+ref);
}
Entity alien = new AlienEntity(this,"http://img101.imageshack.us/img101/9447/alienvx.gif",100+(x*40),(30)+row*30);