我正在制作一个2D平台游戏,并希望地图移动(不是太高级,因为我只在#34; devstage 1")但是当我应用gltranslatef它不会移动所有纹理,只有左上角的纹理。
这是代码,不要担心其他类,因为它们都可以正常工作。
package Window;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import controls.TileChanger;
import Functions.renderer;
import Window.GridHandler;
public class Main {
public static void main(String[] args) {
renderer.begin();
int[][] map = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
GridHandler grid = new GridHandler(map);
TileChanger changer = new TileChanger(grid);
float translate_x = 0;
float translate_y = 0;
int speed = 5;
while(!Keyboard.isKeyDown(Keyboard.KEY_Q)) {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(translate_x, translate_y, 0);
glEnable(GL_TEXTURE_2D);
if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
translate_x += speed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
translate_x -= speed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
translate_y += speed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
translate_y -= speed;
}
changer.Update();
grid.draw();
glPopMatrix();
Display.update();
Display.sync(60);
}
Display.destroy();
System.exit(0);
}
}
有人可以告诉我如何将gltranslatef应用到所有map [] []? 谢谢。