Hallo ich habe eine Frage, ich bin dabei ein "Spiel" zu programmieren, aber ich habe ein Problem.
Ich habe eine Map als Hintergrund des Frames und möchte nun einen Charakter auf das Hintergrundbild zeichnen, wie mache ich das:
Mein Code:
Ich habe eine Map als Hintergrund des Frames und möchte nun einen Charakter auf das Hintergrundbild zeichnen, wie mache ich das:
Mein Code:
Java:
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Game extends JFrame{
Image b;
Image i;
JLabel l;
public Game() {
this.setBounds(0, 0, 500, 500);
ImageIcon i = new ImageIcon("xxx.jpg");
b=new ImageIcon("xxx.jpg").getImage();
l=new JLabel("",i,JLabel.LEFT);
l.setBounds(0, 0, 500, 500);
this.add(l);
this.setVisible(true);
}
public void paint(Graphics g) {
int x=0;
int y=0;
g.drawImage(b, x, y, this);
}
}