2 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超13個(gè)贊
由于移動(dòng)相機(jī)是一種不好的做法,最好移動(dòng)一個(gè)圖層(你的精靈的容器),或者你可以嘗試ScrollPane,WidgetGroup的實(shí)現(xiàn)
ps 在 v. 1.9.11 上測(cè)試

TA貢獻(xiàn)1942條經(jīng)驗(yàn) 獲得超3個(gè)贊
我認(rèn)為這應(yīng)該可以解決問題
public class MovingCamera extends InputAdapter {
OrthographicCamera camera; // The camera to be moved
float pivotX; // The pivot for the movement
public MovingCamera() {
camera = new OrthographicCamera(); // Initialize camera
}
// Create a pivot
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Vector3 unprojected = camera.unproject(new Vector3(screenX, screenY, 0)); // Convert from pixel to world coordinates
pivotX = unprojected.x; // Save first finger touch on screen (Will serve as a pivot)
return true; // Input has been processed
}
// Move the camera
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
Vector3 unprojected = camera.unproject(new Vector3(screenX, screenY, 0)); // Convert from pixel to world coordinates
camera.position.x += unprojected.x - pivotX; // Change camera position
camera.update(); // Apply changes
return true; // Input has been processed
}
}
在您的渲染方法中:
public void render(SpriteBatch spriteBatch) {
spriteBatch.setProjectionMatrix(camera.combined); // Let the Sprite Batch use the camera
spriteBatch.begin();
// [Draw your Textures, TextureRegions, Sprites, etc...]
spriteBatch.end();
}
添加回答
舉報(bào)