当前位置: 首页>>代码示例>>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;未经允许,请勿转载。