0

我对此很陌生。当我遇到一个我没有找到任何解决方案的问题时,我正在尝试创建一个简单的游戏。我一直试图显示的 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() {
}

}

4

1 回答 1

1

问题大概是这个

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

你有一个 1px 宽的渲染区域,大概是 9/16 高。所以大约是 1px * 1px 的屏幕尺寸。如果您在 (10,10) 处绘制左侧纹理,则该纹理已经超出了渲染区域。

这样做:

camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
于 2013-08-21T11:10:48.260 回答