So I’m currently making the MainMenu screen for my game, but I when I try to render both the stage and the logo, it just shows the logo as a big white box on the screen Im a newbie with libGdx so this is probably simple for you experts
Here’s the code:
package com.mayogames.zombiecubes;
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.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
public class MainMenu implements Screen {
ZombieCubes zombieCubes;
Stage stage;
BitmapFont black;
BitmapFont white;
TextureAtlas atlas;
Skin skin;
SpriteBatch batch;
TextButton playButton;
OrthographicCamera camera;
Texture logoTexture;
Sprite logoSprite;
public MainMenu(ZombieCubes zombieCubes){
this.zombieCubes = zombieCubes;
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.act(delta);
batch.begin();
batch.draw(logoSprite, 0, 0);
stage.draw();
batch.end();
}
@Override
public void resize(int width, int height) {
if(stage == null) stage = new Stage(width, height, true);{
stage.clear();
Gdx.input.setInputProcessor(stage);
logoTexture = new Texture(Gdx.files.internal("data/ZombieCubesLogo.png"));
logoTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
logoSprite = new Sprite(logoTexture);
logoSprite.setX(100);
logoSprite.setY(50);
TextButtonStyle style = new TextButtonStyle();
style.up = skin.getDrawable("button");
style.down = skin.getDrawable("buttonpressed");
style.font = white;
playButton = new TextButton("Play!", style);
playButton.setWidth(600);
playButton.setHeight(50);
playButton.setX(Gdx.graphics.getWidth() / 2 - (playButton.getWidth() / 2));
playButton.setY(Gdx.graphics.getHeight() / 2 - (playButton.getHeight() / 2));
stage.addActor(playButton);
}
}
@Override
public void show() {
batch = new SpriteBatch();
atlas = new TextureAtlas("data/button.atlas");
skin = new Skin();
skin.addRegions(atlas);
black = new BitmapFont(Gdx.files.internal("data/black.fnt"), false);
white = new BitmapFont(Gdx.files.internal("data/white.fnt"), false);
}
@Override
public void hide() {
dispose();
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
batch.dispose();
skin.dispose();
atlas.dispose();
black.dispose();
white.dispose();
stage.dispose();
}
}
And yes the image size is PoT