我在一个正在创建的新游戏中有一个测试纹理,由于某种原因,当我将它实现到游戏中时,纹理是水平翻转的,而不是垂直翻转的。为什么会这样?
这是应用程序的照片。
可以看到,小家伙是水平翻转的,几乎就像在睡觉一样。他应该垂直面对。为什么会发生这种情况,我该如何预防?我将发布涉及的两个课程。
球员等级:
import java.io.IOException;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
public class Player {
public Texture playerTexture;
// Positions & speed
public float xPos = 20.0f; // This is initial
public float yPos = 450.0f; // Same as above.
private float velocity = 20;
public float gravityForce = 6;
public float jumpVelocity = 25;
private static int moveSpeed = 30 / 2;
public boolean isSupported = false; // Once again, initial value.
boolean canJump = true;
// movement methods
public Texture grabTexture() {
try {
playerTexture = TextureLoader.
getTexture("PNG", ResourceLoader
.getResourceAsStream
("resources/test_char.png"));
} catch (IOException e) {
e.printStackTrace();
}
return playerTexture;
}
public void applyGravity() {
}
private void printPos(String moveMethod) {
System.out.println(moveMethod + " X: "
+ xPos + " Y: " + yPos);
}
public void moveRight() {
xPos += moveSpeed;
printPos("Moving right!");
}
public void moveLeft() {
xPos -= moveSpeed;
printPos("Moving left!");
}
public void jump() {
if (!isSupported) {
}
}
public void shoot() {
// do shooty stuff here
}
}
主(启动器)类:
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
public class Main {
private void display() {
try {
Display.setDisplayMode(new DisplayMode(1000, 550));
Display.setTitle("Unnamed Platformer Game");
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
// OpenGL
while (!Display.isCloseRequested()) {
initGL();
player.applyGravity();
Display.update();
Display.sync(60); // sync to 60 fps
if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
player.moveRight();
} else if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
player.moveLeft();
} else if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
player.jump();
}
}
Display.destroy();
}
private void initGL() {
// initial OpenGL items for 2D rendering
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 1000, 550, 0, 1, -1);
// start rendering player image
player.grabTexture().bind();
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(player.xPos, player.yPos);
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(player.xPos + 100, player.yPos);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(player.xPos + 100, player.yPos + 100);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(player.xPos, player.yPos + 100);
GL11.glTexCoord2f(0, 1);
GL11.glEnd(); // stop rendering this image
}
Player player = new Player();
public static void main(String[] args) {
Main main = new Main();
main.display();
}
}