libGdx绘制方法没有显示png

时间:2013-08-21 11:01:50

标签: libgdx draw

我是新手。当我遇到一个我没有找到任何解决方案的问题时,我正在尝试创建一个简单的游戏。我一直试图显示的png根本没有显示,没有错误或任何东西。而且我已将它放在屏幕中间,因此它不会超出绘图空间。

我想提前感谢你的答案。 继承我的代码:

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() {
}

}

1 个答案:

答案 0 :(得分:1)

问题可能是这个

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

你有一个1px宽的渲染区域,大概是9/16高。所以大约1px * 1px屏幕大小。如果你在(10,10)处绘制左边纹理,那么它已经在渲染区域之外。

这样做:

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