gpt4 book ai didi

java - 线程 "LWJGL Application"中的异常 youtube tut 以及视频链接

转载 作者:太空宇宙 更新时间:2023-11-04 15:07:20 25 4
gpt4 key购买 nike

我一直在关注本教程:http://www.youtube.com/watch?v=LSblkR4K1LU和每次运行此背景图像时我都会遇到问题,这是控制台中出现的内容如果有人可以帮助我...我不知道我是否遗漏了某些东西或它是什么。我以为是找不到图像,但我尝试通过再次创建文件并确保我正确输入所有内容来修复它。

我得到的错误:

`Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Texture width and height must be powers of two: 1920x1080
at com.badlogic.gdx.graphics.GLTexture.uploadImageData(GLTexture.java:241)
at com.badlogic.gdx.graphics.Texture.load(Texture.java:145)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:112)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:104)
at com.universal.game.Assets.load(Assets.java:15)
at com.universal.game.MyGame.create(MyGame.java:11)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)`

GameScreen.java

package com.universal.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;


public class GameScreen implements Screen {

MyGame game;
OrthographicCamera camera;
SpriteBatch batch;

public GameScreen(MyGame game){
this.game = game;

camera = new OrthographicCamera();
camera.setToOrtho(false,1920,1080);

batch = new SpriteBatch();
}

@Override
public void render(float delta) {
Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

camera.update();
}

@Override
public void show() {

}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void dispose() {

}

@Override
public void resize(int width, int height) {

}

@Override
public void hide() {

}

}

MyGame.java

package com.universal.game;

import com.badlogic.gdx.Game;

public class MyGame extends Game{

public GameScreen game_screen;

@Override
public void create() {
Assets.load();

game_screen = new GameScreen(this);

setScreen(game_screen);


}

}

Assets .java

package com.universal.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;

public class Assets {


public static Texture texture_back;
public static Sprite sprite_back;

public static void load(){
texture_back = new Texture(Gdx.files.internal("menu/back.png"));
texture_back.setFilter(TextureFilter.Linear, TextureFilter.Linear);
sprite_back = new Sprite(texture_back);
sprite_back.flip(false, true);
}

}

Main.java

package com.universal.game;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;

public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "Z-Angel";
cfg.useGL20 = true;
cfg.width = 480;
cfg.height = 320;

new LwjglApplication(new MyGame(), cfg);
}

}

最佳答案

“纹理宽度和高度必须是 2 的幂”

在 GameScreen.java 中,

camera.setToOrtho(false,1920,1080);

1080 和 1920 不是合法值。您必须使用以下值之一:1024、2048、4096

关于java - 线程 "LWJGL Application"中的异常 youtube tut 以及视频链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21810168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com