私はJavaとLWJGLにかなり慣れていません。2D スプライトの外観を変更して、保持している方向を向くようにしようとしていますが、どうすればよいですか?
これまでのところ、私はこれを持っています-
package keyboardinputdb;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class KeyboardInputDB extends JFrame{
//Variables
int x, y, scoreCount;
private Image dbImage;
private Graphics dbg;
Image littleAdventurer;
boolean faceLeft;
boolean faceRight;
boolean faceUp;
Font font = new Font("Arial", Font.BOLD, 18);
//Action Listener
public class AL extends KeyAdapter {
public void keyPressed(KeyEvent e){
int keyCode = e.getKeyCode();
if(keyCode == e.VK_LEFT){
x-=3;
if(x <= 0){
x = 0;
}
}
if(keyCode == e.VK_RIGHT){
x+=3;
if(x >= 235){
x = 235;
}
}
if(keyCode == e.VK_UP){
y-=3;
if(y <= 20){
y = 20;
}
}
if(keyCode == e.VK_DOWN){
y+=3;
if(y >= 235){
y = 235;
}
}
}
public void keyReleased(KeyEvent e){
}
}
public KeyboardInputDB(){
//Load Images
ImageIcon i = new ImageIcon("C:/Users/Clive/Documents/NetBeansProjects/KeyboardInput with DB/src/keyboardinputdb/littleAdventurer.gif");
littleAdventurer = i.getImage();
//Game Properties
addKeyListener(new KeyboardInputDB.AL());
setTitle("Java Game");
setSize(600, 500);
setResizable(false);
setVisible(true);
setBackground(Color.black);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
x = 150;
y = 150;
scoreCount = 0;
}
public void paint(Graphics g){
dbImage = createImage(getWidth(), getHeight());
dbg = dbImage.getGraphics();
paintComponent(dbg);
g.drawImage(dbImage, 0, 0, this);
}
public void paintComponent(Graphics g){
g.setFont(font);
g.setColor(Color.white);
g.drawString("Score: " + scoreCount, 450, 70);
if(faceLeft = true){
g.drawImage(littleAdventurer, x, y, this);
}
else{
g.setColor(Color.white);
g.fillOval(x, y, 15, 15);
}
repaint();
}
public static void main(String[] args) {
KeyboardInputDB javagame = new KeyboardInputDB();
}
}
これについての助けをいただければ幸いです。