gx10001
gx10001

Reputation: 155

libGdx draw method not showing png

im new to this. I'was trying to create a simple game, when I encountered a problem to which I haven't found any solutions. The png I've been trying to display is simply not showing, no errors or anything. And I've put it in the middle of the screen so its not out of the drawing space.

I would like to thank you in advance for the answers. Heres my code:

public class Kurve implements ApplicationListener {
Texture left;
Texture right;
private OrthographicCamera camera;
private SpriteBatch batch;
ShapeRenderer sr;
float w;
float h;
float circleX;
float circleY;
Circle c;

@Override
public void create() {
    w = Gdx.graphics.getWidth();
    h = Gdx.graphics.getHeight();
    sr = new ShapeRenderer();
    camera = new OrthographicCamera(1, h / w);
    batch = new SpriteBatch();
    left = new Texture(Gdx.files.internal("key_left.png"));
    right = new Texture(Gdx.files.internal("key_right.png"));
    circleX = w / 2;
    circleY = 0;
    c = new Circle(circleX, circleY, 5);
    Rectangle leftKey = new Rectangle(0, h / 2, 64, 64);
    Rectangle rightKey = new Rectangle(w - 64, h / 2, 64, 64);

}

@Override
public void dispose() {
    batch.dispose();
    sr.dispose();
}

@Override
public void render() {
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    if (circleY >= h) {
        circleY = 0;
    }
    batch.setProjectionMatrix(camera.combined);

    batch.begin();
    batch.draw(left, 10, 10);
    batch.draw(right, h / 2, w / 2);
    batch.end();

    sr.begin(ShapeType.Filled);
    sr.setColor(1, 0, 0, .3f);
    sr.circle(w / 2, circleY += 1, 5);
    c.set(w / 2, circleY += 1, 5);
    sr.end();

}

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

@Override
public void pause() {
}

@Override
public void resume() {
}

}

Upvotes: 0

Views: 251

Answers (1)

noone
noone

Reputation: 19776

The problem is probably this

camera = new OrthographicCamera(1, h / w);

You have a render area of the size 1px wide and probably something like 9/16 high. So roughly a 1px * 1px screensize. If you draw your left texture at (10,10) that's already out of the rendering area.

Do it this way:

camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

Upvotes: 1

Related Questions