java - Sprite 不显示在 Libgdx 中

标签 java libgdx sprite

我在LibGDX中做了简单的应用。我有两个纹理(背景和 Sprite )。背景显示正常,但我看不到 Sprite 。我尝试了很多解决方案,但没有任何效果。我不知道发生了什么事。感谢您的帮助。

这是我的代码:

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

最佳答案

您的相机视口(viewport)对于 Sprite 位置来说太小

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

Sprite 正在远离视口(viewport)的地方渲染。

尝试像这样设置你的相机:

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

关于java - Sprite 不显示在 Libgdx 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20301097/

相关文章:

java - Android 注释不是用 Ant 编译的

java - (cast)Int 与 float 性能

java - libgdx box2d,以一定角度创建时纹理/主体不在正确位置

ios - Sprite Kit 设置节点角度(不旋转)

unity-game-engine - 在 Unity 中,获取网格物体,还是获取 Sprite 上的局部边界?

java - 组合 getSelectedItem 但然后

java - 使用 Guava 函数将 List<List<String>> 转换为 List<Integer>

java - 尝试更新多对多数据结构时获取 'Multiple representations of the same entity'

java - libGDX 将正交相机沿着纹理移动

swift - 在 Swift 中保存/存档 SKSpriteNode