在我的横向卷轴中,我想要 3 个不断循环的背景。每当您通过一个阶段时,它都会调用函数 nextStage() 将您发送到下一个背景。在课堂里:
package com.erikbalen.game.rpg;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class World extends JPanel implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 2834816426699432121L;
Player p1;
Image background;
Timer time;
public World() {
p1 = new Dps();
addKeyListener(new AL());
setFocusable(true);
ImageIcon icon = new ImageIcon("C:\\Program Files (x86)\\EriksRPG\\Images\\Backgrounds\\background.png");
background = icon.getImage();
time = new Timer(5, this);
time.start();
}
public void actionPerformed(ActionEvent e) {
p1.move();
repaint();
}
public void paint(Graphics g) {
super.paint(g);
Graphics g2d = (Graphics2D) g;
g2d.drawImage(background, 0, 0, null);
g2d.drawImage(p1.getImage(), p1.getX(), p1.getY(), null);
}
private class AL extends KeyAdapter {
public void keyReleased(KeyEvent e) {
p1.keyReleased(e);
}
public void keyPressed(KeyEvent e) {
p1.keyPressed(e);
}
}
}
基本上我想知道如何制作一组称为背景的图像,加载这三个文件,并制作一个名为 nextStage() 的方法loads background[stage] and if stage > 2 stage = 0