Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Sprite粘在libgdx中的相机上?_Java_Opengl_Libgdx_Render_Spritebatch - Fatal编程技术网

Java Sprite粘在libgdx中的相机上?

Java Sprite粘在libgdx中的相机上?,java,opengl,libgdx,render,spritebatch,Java,Opengl,Libgdx,Render,Spritebatch,我想让精灵在我离开的地方出现在屏幕上,并把相机拖动到世界上。但是精灵会粘在相机上,当我拖动相机时,它仍然在屏幕的底部 tilemap(即.tmx文件)和渲染器不会发生这种情况:摄影机可以在tilemap上拖动,而tilemap不会附着到摄影机上。当雪碧拍变硬时,雪碧停留在屏幕底部 这是我的密码: map = MyLoader.manager.get("data/mMap.tmx"); float unitScale = 1 / 64f; renderer = new OrthogonalTile

我想让精灵在我离开的地方出现在屏幕上,并把相机拖动到世界上。但是精灵会粘在相机上,当我拖动相机时,它仍然在屏幕的底部

tilemap(即.tmx文件)和渲染器不会发生这种情况:摄影机可以在tilemap上拖动,而tilemap不会附着到摄影机上。当雪碧拍变硬时,雪碧停留在屏幕底部

这是我的密码:

map = MyLoader.manager.get("data/mMap.tmx");
float unitScale = 1 / 64f;
renderer = new OrthogonalTiledMapRenderer(map, unitScale);

@Override
public void render() {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    camera.update();
    renderer.setView(camera);
    renderer.render();//tilemap works fine

    //sprite
    //batchMap.setProjectionMatrix(camera.combined);//wrong

    batchMap.begin();
    if ( scrFactoryMap.maps.size() > 0 ) {
        scrFactoryMap.getMap(0).draw(batchMap);//sprite sticks to the camera
    }
    str = "string";
    font.draw(batchMap, str, 50,50);//font sticks to the camera
    batchMap.end();
}


private void slerpCamera(){
    //...
    camera.position.add( camX, camY, 0 );
    camera.update();
}

你为什么评论这件事,把它看错了

//sprite
//batchMap.setProjectionMatrix(camera.combined);//wrong
无论何时变换(即移动)相机,都必须将新的ProjectionMatrix设置为SpriteBatch


取消注释:)

我认为这是一个技巧性的问题。评论明确表示,这是“错误的”。这不可能是解决方案!:DTrue,这是一种可能性:P我认为他认为这是错误的,因为当使用投影矩阵和他的相机在0、0的位置时,就好像世界开始在屏幕中间。所以他认为这是错误的:p但实际上他只需要移动他的相机。不太擅长解释..谢谢,你是对的,它几乎可以工作,投影矩阵的问题是我得到了一个黑色矩形,而不是我的精灵,它在右上角,而没有它,精灵显示在左下角,正如预期的那样。您是否知道如何将其与图像一起放回左下角(可能是图像的背面,设置从下到上、从左到右、从后到前进行了反转?)。设置大小(1,1);比如说@如果有人有同样的问题,<代码> SETSIZE 改变宽度/高度,现在我可以把精灵放在中间,只使用<代码> 0,0< /代码>,而不是<代码> -SpRIT.GETWIFTH()/2代码/代码>,这是我必须与<代码> StStase一起使用的。一切都好,谢谢你。