作为我计算机科学课的最后一课,我们可以在Java或某种大型项目中上课。我使用了一个现有的口袋妖怪java引擎,正在构建我的游戏。我遇到的问题是它不是正确的大小(160,144),除非你重新调整框架的大小,否则图像不会显示。如果有人有任何想法为什么那么伟大。此外,图片的路径是正确的,它不会让我出于某种原因发布它们。
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.AffineTransform;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class AnotherIdea {
public static class Engine extends JPanel implements KeyListener, ActionListener {
public static JFrame jf;
public Toolkit tk = jf.getToolkit();
private Image titlescreen = tk.createImage("F:\\Votech Final\\Welcome to Nightvale\\anotherIdea\\src\\Resources\\Tittle.png");
private Image start_symbol = tk.createImage("F:\\Votech Final\\Welcome to Nightvale\\anotherIdea\\src\\Resources\\Start.png");
private boolean atTitle = true;
private boolean atContinueScreen = false;
private boolean start_visible = true;
private boolean gamestarted = false;
private int offsetX = 0, offsetY = 0;
private int TILE_WIDTH_PIXELS = 32;
private int TILE_HEIGHT_PIXELS = 32;
private int concurrentMenuItem = 0;
public long seconds = 0;
public long oldTime;
public long minutes = 0;
public long hours = 0;
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
AffineTransform at = new AffineTransform();
g2.setTransform(at);
if (atTitle == true) {
g.drawImage(titlescreen,0,0,null);
if (start_visible == true) {
g.drawImage(start_symbol,0,260,null);
}
}
}
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
if (atTitle == true) {
if (keyCode == KeyEvent.VK_ENTER) {
atTitle = false;
}
}
}
public static void main(String [] Args) {
//Create the window
jf = new JFrame("T.I.N.");
jf.setSize(160,144);
//Create an instance of Pokemon and insert into the window
Engine engine = new Engine();
jf.add(engine);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setResizable(true);
jf.pack();
//Center the Game on the Screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int w = jf.getSize().width;
int h = jf.getSize().height;
int x = (dim.width-w)/2;
int y = (dim.height-h)/2;
jf.setLocation(x,y);
//Set focus to the Panel
jf.setVisible(true);
engine.requestFocus(true);
}
@Override
public void keyTyped(KeyEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void keyReleased(KeyEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
}
`