2014-10-26 47 views
0

我有一個背景圖片,我希望在屏幕上保持相同的位置。所以,當我用我的飛船前進並移動照相機時,同樣的背景圖像會留在屏幕上。有沒有辦法在屏幕上繪製背景圖像,而不必隨照相機一起移動?像例如使用特殊的圖層或其他東西,所以不需要附加的矩陣轉換來移動BG圖像?在libgdx中繪製背景圖片而不移動精靈以及相機

回答

1

在libGDX相機類中有camera.unproject(Vector2 vector)函數。要將背景圖像放在屏幕上的某個位置,每次繪製時就需要取消投影,並從未投影的座標繪製到精靈批處理中。例如:

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 
+0

完美地工作,謝謝! – gogonapel 2014-10-26 18:29:00