Domanda

i been following this tutorial : http://www.youtube.com/watch?v=LSblkR4K1LU and i have a problem everytime i run this background image here is what comes up in the console if someone can help me out... i dont know if im missing something or what it is. i thought it was the image that couldnt be found but i tried to fix it by making the file again and making sure i typed everything correctly.

error i get:

`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);
}

}

È stato utile?

Soluzione

"Texture width and height must be powers of two"

In GameScreen.java,

camera.setToOrtho(false,1920,1080);

The 1080 and 1920 is not a legitimate value. You must use one of these values: 1024, 2048, 4096

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top