當前位置: 首頁>>代碼示例>>Java>>正文


Java OrthographicCamera.translate方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.graphics.OrthographicCamera.translate方法的典型用法代碼示例。如果您正苦於以下問題:Java OrthographicCamera.translate方法的具體用法?Java OrthographicCamera.translate怎麽用?Java OrthographicCamera.translate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.graphics.OrthographicCamera的用法示例。


在下文中一共展示了OrthographicCamera.translate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateCameraPosition

import com.badlogic.gdx.graphics.OrthographicCamera; //導入方法依賴的package包/類
/**
 * Update the camera target follows the predicated x and y parameters
 * smoothly
 * 
 * @param gameTime
 * @param cameraSpeed
 * @param x
 * @param y
 */
protected void updateCameraPosition(float gameTime, int cameraSpeed,
		float x, float y) {

	OrthographicCamera camera = services.getCamera();
	float oldX = camera.position.x;
	float oldY = camera.position.y;

	if (camera.position.x > x + 1) {
		camera.translate(new Vector2(-cameraSpeed, 0));
	}
	if (camera.position.x < x - 1) {
		camera.translate(new Vector2(cameraSpeed, 0));
	}
	if (camera.position.y > y + 1) {
		camera.position.y -= cameraSpeed;
	}
	if (camera.position.y < y - 1) {
		camera.position.y += cameraSpeed;
	}

	if (camera.position.x < Gdx.graphics.getWidth() / (2 / camera.zoom)
			|| camera.position.x > getMapWidth() - Gdx.graphics.getWidth()
					/ (2 / camera.zoom)) {

		camera.position.x = oldX;
	}
	if (camera.position.y < Gdx.graphics.getHeight() / (2 / camera.zoom)
			|| camera.position.y > getMapHeight()
					- Gdx.graphics.getHeight() / (2 / camera.zoom)) {
		camera.position.y = oldY;
	}
}
 
開發者ID:game-libgdx-unity,項目名稱:GDX-Engine,代碼行數:42,代碼來源:TiledScene.java

示例2: adjustCamera

import com.badlogic.gdx.graphics.OrthographicCamera; //導入方法依賴的package包/類
public static void adjustCamera(OrthographicCamera camera, HexMap<TileData> grid)
{

    double maxHeight = -1, maxWidth = -1;
    double minHeight = Double.MAX_VALUE, minWidth = Double.MAX_VALUE;
    for(int i = 0; i < grid.getHexs().length; i++)
    {
        Hexagon<TileData> hex = grid.getHexs()[i];
        TileData data = hex.getHexData();
        hex.setHexData(data);


        for(Point p : hex.getHexGeometry().getPoints())
        {
            if(p.y < minHeight)
                minHeight = p.y;

            if(p.y > maxHeight)
                maxHeight = p.y;

            if(p.x < minWidth)
                minWidth = p.x;

            if(p.x > maxWidth)
                maxWidth = p.x;
        }
    }

    double deltaX = maxWidth - minWidth;
    double middleX = minWidth + deltaX/2;

    double deltaY = maxHeight - minHeight;
    double middleY = minHeight + deltaY/2;

    camera.translate((float) middleX, (float) (middleY - 50), 0);

    double biggestDelta = deltaY;

    camera.zoom = (float) (biggestDelta / 500);
    camera.update();
}
 
開發者ID:MartensCedric,項目名稱:Hexpert,代碼行數:42,代碼來源:MapUtils.java


注:本文中的com.badlogic.gdx.graphics.OrthographicCamera.translate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。