com.badlogic.gdx.graphics.OrthographicCamera Java Examples

The following examples show how to use com.badlogic.gdx.graphics.OrthographicCamera. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Renderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
public Renderer (OrthographicCamera cam, Worm worm, Food food, Level level) {
	font = new BitmapFont(Gdx.files.internal(FONT_LOC));
	this.cam = cam;
	this.worm = worm;
	wholeWorm = worm.getAllBody();
	this.food = food;
	levelArray = level.getLevelArray();
	shapeRenderer = new ShapeRenderer();
	random = new Random();
	color = new Color();
	color.r = Color.WHITE.r;
	color.g = Color.WHITE.g;
	color.b = Color.WHITE.b;
	color.a = Color.WHITE.a;
	rect = new Rectangle();
	batch = new SpriteBatch();
}
 
Example #2
Source File: ClientDiscoveryScreen.java    From killingspree with MIT License 6 votes vote down vote up
@Override
public void show() {
    client = new Client();
    client.start();
    font = game.getFont(120);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    viewport = new FitViewport(1280, 720, camera);
    camera.setToOrtho(false, 1280, 720);
    buttons = new ArrayList<MyButton>();
    ipAddresses = new ArrayList<MyButton>();
    markForDispose = false;
    addAllButtons();
    addIpButtons();
    pressedButton = false;
}
 
Example #3
Source File: WorldRenderer.java    From killingspree with MIT License 6 votes vote down vote up
public WorldRenderer(WorldManager worldManager, Client client, KillingSpree game) {
    worldMap = new ConcurrentHashMap<Short, ClientEntity>();
    this.worldManager = worldManager;
    audioPlayer = new SFXPlayer();
    stateProcessor = new StateProcessor(client, worldMap, audioPlayer,
            game.platformServices);
    if (worldManager != null) {
        debugRenderer = new WorldDebugRenderer(worldManager.getWorld());
        worldManager.setOutgoingEventListener(stateProcessor);
    } else {
        this.client = client;
    }
    camera = new OrthographicCamera();
    batch = new SpriteBatch();
    controlsSender = new ControlsSender();
    recentId = -2;
    screenShakeX = 0;
    screenShakeY = 0;
    screenShakeTime = 0;
    hudRenderer = new HUDRenderer();
    this.game = game;
}
 
Example #4
Source File: ViewportsDemo.java    From ud405 with MIT License 6 votes vote down vote up
/**
     * Uncomment the following viewports one at a time, and check out the effect when you resize the desktop window.
     */
    @Override
    public void create() {
        camera = new OrthographicCamera();

        // Makes the size of the world match the size of the screen
        viewport = new ScreenViewport(camera);

        // Make the world fill the screen, regardless of aspect ratio
//        viewport = new StretchViewport(WORLD_WIDTH, WORLD_HEIGHT, camera);

        // Make the world fill the screen, maintaining aspect ratio, but bits of the world may be cut off
//        viewport = new FillViewport(WORLD_WIDTH, WORLD_HEIGHT, camera);

        // Fit the world inside the screen, adding black bars to pad out the extra space, maintaining aspect ratio
//        viewport = new FitViewport(WORLD_WIDTH, WORLD_HEIGHT, camera);

        // Make the short axis of the world larger to fill the screen, maintaining aspect ratio
//        viewport = new ExtendViewport(WORLD_WIDTH, WORLD_HEIGHT, camera);


        viewport.setScreenBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        renderer = new ShapeRenderer();
    }
 
Example #5
Source File: AzurLaneSpineCharacterDecoder.java    From AzurLaneSpineCharacterDecoder with MIT License 6 votes vote down vote up
@Override
public void create() {
	batch = new SpriteBatch();
	img = new Texture("core/assets/WatchDog.png");
	camera = new OrthographicCamera();
	camera.setToOrtho(false);

	spineKeeperArray = new Array<PerSpineKeeper>();
	if (jsonType) {
		JsonReader reader = new JsonReader();
		JsonValue jsonValue = reader.parse(Gdx.files.absolute(args.get(0)));
		System.out.println();
		array = jsonValue.asStringArray();
		size = array.length;
	}
	path = System.getProperty("user.dir");

	scale=Float.parseFloat(Gdx.files.internal("core/assets/scale.txt").readString());
}
 
Example #6
Source File: WorldRenderer.java    From xibalba with MIT License 6 votes vote down vote up
/**
 * Setup world renderer.
 *
 * @param worldCamera Instance of camera
 * @param batch       Instance of sprite batch
 */
public WorldRenderer(OrthographicCamera worldCamera, SpriteBatch batch) {
  this.worldCamera = worldCamera;
  this.batch = batch;

  viewport = new FitViewport(960, 540, worldCamera);

  playerDetails = ComponentMappers.player.get(WorldManager.player);
  playerAttributes = ComponentMappers.attributes.get(WorldManager.player);
  playerPosition = ComponentMappers.position.get(WorldManager.player);
  god = ComponentMappers.god.get(WorldManager.god);

  shadow = Main.asciiAtlas.createSprite("1113");
  question = Main.asciiAtlas.createSprite("1503");

  BitmapFont font = new BitmapFont();
  font.getData().setScale(.25f);
}
 
Example #7
Source File: ProfilerSystem.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
protected void initialize() {
  camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  camera.setToOrtho(false);
  camera.update();
  renderer = new ShapeRenderer();
  stage = new Stage();
  stage.getBatch().setProjectionMatrix(camera.combined);
  skin = new Skin(Gdx.files.internal("profiler/uiskin.json"));

  // setup some static config like colors etc
  SystemProfilerGUI.GRAPH_H_LINE.set(Color.ORANGE);
  gui = new SystemProfilerGUI(skin, "default");
  gui.setResizeBorder(8);
  gui.show(stage);
  world.inject(gui, true);
  gui.initialize();
}
 
Example #8
Source File: RadixClient.java    From Radix with MIT License 6 votes vote down vote up
private void setupOGL() {
    camera = new PerspectiveCamera(90, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.position.set(10f, 150f, 10f);
    camera.lookAt(0, 0, 0);
    camera.near = 0.1f;
    camera.far = 450f;
    camera.update();
    hudCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    guiBatch = new SpriteBatch();
    guiBatch.setProjectionMatrix(hudCamera.combined);

    if(android) {
        setupTouchControls();
    }

    Gdx.input.setInputProcessor(new RadixInputHandler(this));

    if(settingsManager.getVisualSettings().getNonContinuous().getValue()) {
        Gdx.graphics.setContinuousRendering(false);
    }

    sceneTheme = new SceneTheme();
    sceneTheme.init();
}
 
Example #9
Source File: CarStillModel.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
private Vector3 world2Dto3D (PerspectiveCamera camPersp, OrthographicCamera camOrtho, float posPxX, float posPxY) {
	float meshZ = -(camPersp.far - camPersp.position.z) + (camPersp.far * (1 - (camOrtho.zoom)));

	// compute position
	tmpvec.x = (this.positionOffsetPx.x - camPersp.position.x) + (camPersp.viewportWidth / 2) + posPxX;
	tmpvec.y = (this.positionOffsetPx.y + camPersp.position.y) + (camPersp.viewportHeight / 2) - posPxY;
	tmpvec.z = 1;

	tmpvec.x *= ScaleUtils.Scale;
	tmpvec.y *= ScaleUtils.Scale;

	tmpvec.x += ScaleUtils.CropX;
	tmpvec.y += ScaleUtils.CropY;

	// transform to world space
	camPersp.unproject(tmpvec, ScaleUtils.CropX, ScaleUtils.CropY, ScaleUtils.PlayWidth, ScaleUtils.PlayHeight);

	// build model matrix
	tmpvec.z = meshZ;

	return tmpvec;
}
 
Example #10
Source File: GameWorldRenderer.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
private void createCams () {
	int refW = Config.Graphics.ReferenceScreenWidth;
	int refH = Config.Graphics.ReferenceScreenHeight;

	camOrtho = new OrthographicCamera(refW, refH);
	halfViewport.set(camOrtho.viewportWidth / 2, camOrtho.viewportHeight / 2);

	// creates and setup orthographic camera
	camTilemap = new OrthographicCamera(refW, refH);
	camTilemap.zoom = 1;

	// creates and setup perspective camera
	// strategically choosen near/far planes, Blender models' 14.2 meters <=> one 256px tile
	// with far plane @48
	camPersp = new PerspectiveCamera(47.27123f, refW, refH);
	camPersp.near = CamPerspPlaneNear;
	camPersp.far = CamPerspPlaneFar;
	camPersp.lookAt(0, 0, -1);
	camPersp.position.set(camTilemap.position.x, camTilemap.position.y, CamPerspElevation);
	camPersp.update();

	camController = new CameraController(Config.Graphics.CameraInterpolationMode, halfViewport, world.worldSizePx,
		world.worldSizeTiles);
}
 
Example #11
Source File: MainMenu.java    From Radix with MIT License 6 votes vote down vote up
public void init() {
    if (!initialized) {
        camera = new OrthographicCamera();
        batch = new SpriteBatch();
        batch.setTransformMatrix(RadixClient.getInstance().getHudCamera().combined);
        batch.setTransformMatrix(camera.combined);
        mmButtonTexture = new Texture(Gdx.files.internal("textures/gui/mmBtn.png"));

        buttonFont = new BitmapFont();

        resize();
        rerender();

        initialized = true;
    }
}
 
Example #12
Source File: HelpScreen.java    From FruitCatcher with Apache License 2.0 6 votes vote down vote up
@Override
public void show() {
       imageProvider = game.getImageProvider();
       backgroundImage = imageProvider.getBackgroundSpring();
       buttons = new Button [1];
       buttons[0] = new Button(imageProvider.getBack());        
       camera = new OrthographicCamera();
       camera.setToOrtho(false, imageProvider.getScreenWidth(), imageProvider.getScreenHeight());
       batch = new SpriteBatch();
       
       buttons[0].setPos(10, 10);
       
       font = new BitmapFont(Gdx.files.internal("fonts/poetsen.fnt"),
       			 		  Gdx.files.internal("fonts/poetsen.png"), false);
       
       startLine = 0;
       lineHeight = 30;
       lastLineIndex = game.getTextResources().getHelpLines().length - 1; 
       
       Gdx.input.setInputProcessor(this);
       Gdx.input.setCatchBackKey(true);        
}
 
Example #13
Source File: ChestBlock.java    From TerraLegion with MIT License 6 votes vote down vote up
/**
 * @return Whether the chest is being tapped
 */
public boolean isTapped(OrthographicCamera camera, float blockX, float blockY){
    this.mousePosition.set(Gdx.input.getX(), Gdx.input.getY(), 0);
    this.mousePosition = camera.unproject(mousePosition);

    if(this.mouseBounds == null){
        this.mouseBounds = new Rectangle(mousePosition.x, mousePosition.y, 0, 0);
    }

    this.mouseBounds.set(this.mousePosition.x, this.mousePosition.y, 0, 0);

    if(this.getBody(blockX, blockY).getBounds().overlaps(mouseBounds) && Gdx.input.isButtonPressed(Input.Buttons.LEFT)){
        return true;
    }

    return false;
}
 
Example #14
Source File: TileMap.java    From Unlucky with MIT License 6 votes vote down vote up
/**
 * Renders the bottom layer as the deepest part of the map
 *
 * @param batch
 */
public void renderBottomLayer(SpriteBatch batch, OrthographicCamera cam) {
    for (int i = 0; i < bottomLayer.length; i++) {
        if (tileInsideCamera(tileMap[i], cam)) {
            int r = i / mapWidth;
            int c = i % mapWidth;

            if (bottomLayer[i] != null)
                batch.draw(bottomLayer[i], origin.x + c * tileSize, origin.y + r * tileSize);
            // render animated tiles below the player
            if (tileMap[i].animated) {
                batch.draw(tileMap[i].anim.getKeyFrame(true), origin.x + c * tileSize, origin.y + r * tileSize);
            }
            // rendering non animated special tiles
            if (!tileMap[i].animated && tileMap[i].isSpecial() && tileMap[i].sprite != null) {
                batch.draw(tileMap[i].sprite, origin.x + c * tileSize, origin.y + r * tileSize);
            }
            // drawing an entity on a Tile
            if (tileMap[i].containsEntity()) {
                tileMap[i].getEntity().render(batch, true);
            }
        }
    }
}
 
Example #15
Source File: Raycaster.java    From raycaster with MIT License 5 votes vote down vote up
@Override
public void create () {
   // Setup 2d camera with top left coordinates
   // http://stackoverflow.com/questions/7708379/changing-the-coordinate-system-in-libgdx-java/7751183#7751183
   // This forces us to flip textures on the y axis, eg. in Camera#drawSky
   orthoCamera = new OrthographicCamera(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
   orthoCamera.setToOrtho(true, VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
   
   this.player = new Player(15.3, -1.2, Math.PI * 0.3);
   this.map = new Map(32);
   this.controls = new Controls();
   this.camera = new Camera(orthoCamera, 320, Math.PI * 0.4);

   this.map.randomize();
}
 
Example #16
Source File: MainMenuScreen.java    From killingspree with MIT License 5 votes vote down vote up
@Override
public void show() {
    font = game.getFont(170);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    viewport = new FitViewport(1280, 720, camera);
    camera.setToOrtho(false, 1280, 720);
    buttons = new ArrayList<MyButton>();
    addAllButtons();
    final Preferences prefs = Gdx.app.getPreferences("profile");
    String name = prefs.getString("name");
    name = name.trim();
    if (name.length() == 0) {
        Gdx.input.getTextInput(new TextInputListener() {
            
            @Override
            public void input(String text) {
                prefs.putString("name", text);
                prefs.flush();
            }
            
            @Override
            public void canceled() {
            }
        }, "Enter name", "");
    }
}
 
Example #17
Source File: Box2DDebugger.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
protected void initialize() {
  setEnabled(false);
  renderer = new Box2DDebugRenderer();
  camera = new OrthographicCamera();
  camera.setToOrtho(true);
  camera.near = -1024;
  camera.far  =  1024;
  camera.rotate(Vector3.X, -60);
  camera.rotate(Vector3.Z, -45);
}
 
Example #18
Source File: HighscoresScreen.java    From ashley-superjumper with Apache License 2.0 5 votes vote down vote up
public HighscoresScreen (SuperJumper game) {
	this.game = game;

	guiCam = new OrthographicCamera(320, 480);
	guiCam.position.set(320 / 2, 480 / 2, 0);
	backBounds = new Rectangle(0, 0, 64, 64);
	touchPoint = new Vector3();
	highScores = new String[5];
	for (int i = 0; i < 5; i++) {
		highScores[i] = i + 1 + ". " + Settings.highscores[i];
		layout.setText(Assets.font, highScores[i]);
		xOffset = Math.max(layout.width, xOffset);
	}
	xOffset = 160 - xOffset / 2 + Assets.font.getSpaceWidth() / 2;
}
 
Example #19
Source File: OrthographicCameraExercise.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void create() {
    renderer = new ShapeRenderer();
    timeCreated = TimeUtils.millis();

    // TODO: Initialize the camera
    camera = new OrthographicCamera();

    // TODO: Set the camera's position to the center of the circle's movement (X_CENTER, Y_CENTER)
    camera.position.set(X_CENTER, Y_CENTER, 0);
}
 
Example #20
Source File: GameScreen.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
@Override
public void show() {    	
       imageProvider = game.getImageProvider();
       soundManager = game.getSoundManager();
   	
       camera = new OrthographicCamera();
       camera.setToOrtho(false, imageProvider.getScreenWidth(), 
       						 imageProvider.getScreenHeight());
       batch = new SpriteBatch();
       
       basketRegion = imageProvider.getBasket();
       basket = new Basket(imageProvider.getScreenWidth(), st.basketX);

       fallingObjectFactory = new FallingObjectFactory(imageProvider);
       
       timesTwoAnimations = new Array<TimesTwoAnimation>();
       
       clock = new AnalogueClock(imageProvider);
       
       numberBoard = new NumberBoard(imageProvider);
       
       backButton = new Button(imageProvider.getBack());
       backButton.setPos(10, 10);
       
       pauseTexture = imageProvider.getPause();
       pauseX = (imageProvider.getScreenWidth() - pauseTexture.getRegionWidth())/2;
       pauseY = (imageProvider.getScreenHeight() - pauseTexture.getRegionHeight())/2;
       
       initGame();        
       
       Gdx.input.setInputProcessor(this);
       Gdx.input.setCatchBackKey(true);
}
 
Example #21
Source File: SplashScreen.java    From killingspree with MIT License 5 votes vote down vote up
@Override
public void show() {
    font = game.getFont(200);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    viewport = new FitViewport(1280, 720, camera);
    camera.setToOrtho(false, 1280, 720);
}
 
Example #22
Source File: MainMenuScreen.java    From ashley-superjumper with Apache License 2.0 5 votes vote down vote up
public MainMenuScreen (SuperJumper game) {
	this.game = game;

	guiCam = new OrthographicCamera(320, 480);
	guiCam.position.set(320 / 2, 480 / 2, 0);
	soundBounds = new Rectangle(0, 0, 64, 64);
	playBounds = new Rectangle(160 - 150, 200 + 18, 300, 36);
	highscoresBounds = new Rectangle(160 - 150, 200 - 18, 300, 36);
	helpBounds = new Rectangle(160 - 150, 200 - 18 - 36, 300, 36);
	touchPoint = new Vector3();
}
 
Example #23
Source File: SplashScreen.java    From libgdx-utils with MIT License 5 votes vote down vote up
@Override
public void show() {
	LibgdxUtils.assets.load("textures/splash.png", Texture.class);
	LibgdxUtils.assets.finishLoading();
	splash = LibgdxUtils.assets.get("textures/splash.png", Texture.class);

	LibgdxUtils.assets.load("skins/uiskin.json", Skin.class);
	LibgdxUtils.assets.load("icons/icons.atlas", TextureAtlas.class);

	camera = new OrthographicCamera();
	viewport = new FitViewport(splash.getWidth(), splash.getHeight(), camera);
}
 
Example #24
Source File: ParticleFactory.java    From Unlucky with MIT License 5 votes vote down vote up
public ParticleFactory(OrthographicCamera cam, final ResourceManager rm) {
    this.cam = cam;
    this.viewWidth = (int) cam.viewportWidth;
    this.viewHeight = (int) cam.viewportHeight;
    this.rm = rm;

    particles = new Array<Particle>();
    particlePool = new Pool<Particle>() {
        @Override
        protected Particle newObject() {
            return new Particle();
        }
    };
}
 
Example #25
Source File: PlantBlock.java    From TerraLegion with MIT License 5 votes vote down vote up
@Override
public void render(OrthographicCamera camera, SpriteBatch sb, float x, float y, float lightValue){
    super.render(camera, sb, x, y, lightValue);

    Vector2 tilePosition = new Vector2(chunkManager.pixelToTilePosition(x), chunkManager.pixelToTilePosition(y));
    Vector2 belowTilePosition = new Vector2(tilePosition.x, tilePosition.y - 1);

    if(chunkManager.getBlockFromTilePos((int) belowTilePosition.x, (int) belowTilePosition.y) == BlockType.AIR){
        chunkManager.setBlock(BlockType.AIR, (int) tilePosition.x, (int) tilePosition.y, true);
    }
}
 
Example #26
Source File: FluidSimulatorSPH.java    From fluid-simulator-v2 with Apache License 2.0 5 votes vote down vote up
public FluidSimulatorSPH(FluidSimulatorStarter fluidSimulatorStarter) {
	super(fluidSimulatorStarter);
	batch = new SpriteBatch(IS_DESKTOP ? 5460 : ANDROID_SIZE);
	font = new BitmapFont();
	camera = new OrthographicCamera(WORLD_WIDTH, WORLD_HEIGHT);
	camera.position.set(0, (WORLD_HEIGHT / 2) - 1, 0);
}
 
Example #27
Source File: GameCamera.java    From libgdx-2d-tutorial with MIT License 5 votes vote down vote up
public GameCamera (int width, int height) {
	cam = new OrthographicCamera();
	viewport = new StretchViewport(width, height, cam);
	viewport.apply();
	cam.position.set(width / 2, height / 2, 0);
	cam.update();
}
 
Example #28
Source File: GameScreen.java    From Unlucky with MIT License 5 votes vote down vote up
public GameScreen(final Unlucky game, final ResourceManager rm) {
    super(game, rm);

    currentEvent = EventState.MOVING;

    gameMap = new GameMap(this, game.player, rm);
    battle = new Battle(this, gameMap.tileMap, gameMap.player);
    hud = new Hud(this, gameMap.tileMap, gameMap.player, rm);
    battleUIHandler = new BattleUIHandler(this, gameMap.tileMap, gameMap.player, battle, rm);
    transition = new TransitionScreen(this, battle, battleUIHandler, hud, gameMap.player, rm);
    levelUp = new LevelUpScreen(this, gameMap.tileMap, gameMap.player, rm);
    dialog = new DialogScreen(this, gameMap.tileMap, gameMap.player, rm);

    // create bg
    bg = new Background[2];
    // sky
    bg[0] = new Background((OrthographicCamera) battleUIHandler.getStage().getCamera(), new Vector2(0.3f, 0));
    // field
    bg[1] = new Background((OrthographicCamera) battleUIHandler.getStage().getCamera(), new Vector2(0, 0));


    // input multiplexer
    multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(hud.getStage());
    multiplexer.addProcessor(battleUIHandler.getStage());
    multiplexer.addProcessor(levelUp.getStage());
    multiplexer.addProcessor(dialog.getStage());
}
 
Example #29
Source File: AbstractScreen.java    From Unlucky with MIT License 5 votes vote down vote up
public AbstractScreen(final Unlucky game, final ResourceManager rm) {
    this.game = game;
    this.rm = rm;

    cam = new OrthographicCamera(Unlucky.V_WIDTH, Unlucky.V_HEIGHT);
    cam.setToOrtho(false);
    // the game will retain it's scaled dimensions regardless of resizing
    viewport = new StretchViewport(Unlucky.V_WIDTH, Unlucky.V_HEIGHT, cam);

    stage = new Stage(viewport, game.batch);
}
 
Example #30
Source File: UI.java    From Unlucky with MIT License 5 votes vote down vote up
public UI(GameScreen gameScreen, TileMap tileMap, Player player, ResourceManager rm) {
    this.game = gameScreen.getGame();
    this.gameScreen = gameScreen;
    this.tileMap = tileMap;
    this.player = player;
    this.rm = rm;

    viewport = new StretchViewport(Unlucky.V_WIDTH, Unlucky.V_HEIGHT, new OrthographicCamera());
    stage = new Stage(viewport, gameScreen.getBatch());

    shapeRenderer = new ShapeRenderer();
}