繁体   English   中英

Sprite不在Libgdx中显示

[英]Sprite doesn't display in Libgdx

我在LibGDX中简单地进行了应用。 我有两个纹理(背景和精灵)。 背景显示正常,但我看不到精灵。 我尝试了许多解决方案,但没有任何效果。 我不知道怎么回事。 感谢帮助。

这是我的代码:

public void create() {      
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    Texture.setEnforcePotImages(false);
    camera = new OrthographicCamera(1, h/w);
    batch = new SpriteBatch();
    texture = new Texture(Gdx.files.internal("graphic/bg1.png"));
    bad = new Texture(Gdx.files.internal("graphic/b.png"));
    layerOne = new TextureRegion(texture);
    spriteb = new Sprite(bad);
    rbg = new ParallaxBackground(new ParallaxLayer[]{
            new ParallaxLayer(layerOne, new Vector2(),new Vector2()),
            }, w, h,new Vector2());
}

public void render() {      
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    rbg.render();
    camera.update();
    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    spriteb.setPosition(400, 200);
    spriteb.draw(batch);
    batch.end();
}

您的摄影机视口对于Sprite位置而言太小

camera = new OrthographicCamera(1, h/w);
...
spriteb.setPosition(400, 200);

该精灵将被渲染到视口之外。

尝试像这样设置相机:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM