繁体   English   中英

在libgdx中绘制背景图像而无需将精灵与相机一起移动

[英]Draw background image in libgdx without moving the sprite along with the camera

我有一个希望保留在屏幕上相同位置的背景图像。 因此,当我推进宇宙飞船并与宇宙飞船一起移动相机时,相同的背景图像将停留在屏幕上。 有没有一种方法可以在屏幕上绘制背景图像而不必将其随相机一起移动? 举例来说,使用特殊的图层或其他东西,这样就不需要其他矩阵平移来移动BG图像了吗?

libGDX相机类中有camera.unproject(Vector2 vector)函数。 要将背景图像放置在屏幕上的某个位置,您只需要在每次绘制时取消投影,然后从未投影的坐标绘制到Sprite批处理上。 例如:

Vector2 position  = new Vector2(10,10); //Can be anything, the x and y of where the background should be
camera.unproject(position); //Unproject the co-ordinates to the position of the camera, this will be stored back in the position vector

batch.draw(background, position.x, position.y); //You can then draw to your sprite batch from the unprojected co-ordinates

暂无
暂无

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

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