Example usage for com.badlogic.gdx.graphics OrthographicCamera OrthographicCamera

List of usage examples for com.badlogic.gdx.graphics OrthographicCamera OrthographicCamera

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics OrthographicCamera OrthographicCamera.

Prototype

public OrthographicCamera() 

Source Link

Usage

From source file:MyGdxGame.java

License:Apache License

@Override
public void create() {
    // load the koala frames, split them, and assign them to Animations
    koalaTexture = new Texture("koalio.png");
    TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0];
    stand = new Animation(0, regions[0]);
    jump = new Animation(0, regions[1]);
    walk = new Animation(0.15f, regions[2], regions[3], regions[4]);
    walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);

    // figure out the width and height of the koala for collision
    // detection and rendering by converting a koala frames pixel
    // size into world units (1 unit == 16 pixels)
    Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth();
    Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight();

    // load the map, set the unit scale to 1/16 (1 unit == 16 pixels)
    map = new TmxMapLoader().load("level1.tmx");
    renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f);

    // create an orthographic camera, shows us 30x20 units of the world
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 30, 20);/*w w w  . j  a v  a 2 s .  co  m*/
    camera.update();

    // create the Koala we want to move around the world
    koala = new Koala();
    koala.position.set(20, 20);
}

From source file:apps101.libgdx_demo.Game.java

License:Open Source License

@Override
public void create() {
    camera = new OrthographicCamera();
    camera.setToOrtho(false, CAMERA_WIDTH, CAMERA_HEIGHT); // the camera is like a window into our game world
    batch = new SpriteBatch();

    /** Instantiate smiley face image **/
    smileyface = new Texture(Gdx.files.internal("128px-Yellow_Happy.jpg"));
    rect_smiley = new Rectangle();
    rect_smiley.width = 128; // "Yellow_Happy.jpg" is 128x128 pixels
    rect_smiley.height = 128;//from   w ww. j  a  v a2  s .c o m
    rect_smiley.x = (CAMERA_WIDTH / 2) - (rect_smiley.width / 2); // center the image horizontally
    rect_smiley.y = (CAMERA_HEIGHT / 2) - (rect_smiley.height / 2); // center the image vertically

    /** Instantiate hello world image **/
    helloworld = new Texture(Gdx.files.internal("helloworld.png"));
    rect_hello = new Rectangle();
    rect_hello.width = 256; // "helloworld.png" is 256x64 pixels
    rect_hello.height = 64;
    rect_hello.x = (CAMERA_WIDTH / 2) - (rect_hello.width / 2); // center the image horizontally
    rect_hello.y = rect_smiley.y + 200; // place helloworld just above the smiley face
}

From source file:at.therefactory.jewelthief.JewelThief.java

License:Open Source License

@Override
public void create() {
    instance = this;

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
            Gdx.files.internal("fonts/amiga4ever pro2.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = 8;//from   w  w  w .  j a v a 2  s . c o  m
    parameter.mono = true;
    font = generator.generateFont(parameter);
    generator.dispose();

    batch = new SpriteBatch();
    shapeRenderer = new ShapeRenderer();
    camera = new OrthographicCamera();
    viewport = new FitViewport(WINDOW_WIDTH, WINDOW_HEIGHT, camera);
    camera.position.set(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 0);
    camera.update();

    textureAtlas = new TextureAtlas("textures.pack");
    assetManager = new AssetManager();

    fade = textureAtlas.createSprite("fade");
    fade.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    fade.setPosition(0, 0);

    particles = new Particles(textureAtlas);

    loadInitialPreferences();
    loadAssets();
    tryToSubmitLatestHighscores();

    // load and show logo screen
    theRefactoryLogoScreen = new LogoScreen(batch, shapeRenderer, viewport, camera);
    setScreen(theRefactoryLogoScreen);
}

From source file:awakening.view.menu.Audio.java

License:Apache License

/**
 * Constructor/*from ww  w  .  ja  v  a  2  s.com*/
 * 
 * @param game Tower Awakening's Game
 * @param sound Main menu's music
 * @param effect Button's effect
 */
public Audio(TAGame game, Music sound, Sound effect) {
    this.game = game;
    this.sound = sound;
    this.effect = effect;
    stage = new Stage();

    try {
        if (game.getLanguage().equals("ENGLISH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_en_EN", locales[0]);
        } else if (game.getLanguage().equals("FRENCH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_fr_FR", locales[1]);
        } else if (game.getLanguage().equals("ITALIAN")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_it_IT", locales[2]);
        } else {
            language = ResourceBundle.getBundle("awakening.view.menu.res", locales[0]);
        }
    } catch (java.util.MissingResourceException e) {
        System.out.println("yolo");
    }

    ///Viewport
    camera = new OrthographicCamera();
    view = new StretchViewport(Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getWidth(), camera);

    ///Background
    background = new Texture(Gdx.files.internal("img/menu/Background-2.png"));
    batch = new SpriteBatch();

    ///Skin
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    ///Title
    title = new Label(language.getString("button_audio"), skin);

    ///Widgets Background
    widgetsBackground = new Image(new Texture(Gdx.files.internal("img/widget/bg widgets.png")));

    ///Back Button
    btnBack = new TextButton(language.getString("button_back"), skin);

    ///Music Slider
    sliderMusic = new Slider(0, 10, 1, false, skin);

    ///Music Label
    musicLabel = new Label(language.getString("label_music_volume"), skin);

    ///Sound Slider
    sliderEffects = new Slider(0, 10, 1, false, skin);

    ///Sound Label
    soundLabel = new Label(language.getString("label_effect_volume"), skin);
}

From source file:awakening.view.menu.Controls.java

License:Apache License

/**
 * Constructor/*from  w  ww .j  av  a  2  s  .  c o  m*/
 * 
 * @param game Tower Awakening's Game
 * @param sound Main menu's music
 * @param effect Button's effect
 */
public Controls(TAGame game, Music sound, Sound effect) {
    this.game = game;
    this.sound = sound;
    this.effect = effect;
    stage = new Stage();

    ///Language
    try {
        if (game.getLanguage().equals("ENGLISH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_en_EN", locales[0]);
        } else if (game.getLanguage().equals("FRENCH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_fr_FR", locales[1]);
        } else if (game.getLanguage().equals("ITALIAN")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_it_IT", locales[2]);
        } else {
            language = ResourceBundle.getBundle("awakening.view.menu.res", locales[0]);
        }
    } catch (java.util.MissingResourceException e) {
        System.out.println("yolo");
    }

    ///Viewport
    camera = new OrthographicCamera();
    view = new StretchViewport(Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getWidth(), camera);

    ///Background
    background = new Texture(Gdx.files.internal("img/menu/Background-4.png"));
    batch = new SpriteBatch();

    ///Skin
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    ///Title
    title = new Label(language.getString("label_controls_menu"), skin);

    ///Background Widget
    widgetsBackground = new Image(new Texture(Gdx.files.internal("img/widget/window_large.png")));

    ///Langage Checkbox
    lblLangage = new Label(language.getString("label_language"), skin);
    String[] lang = { "English", "Francais", "Italiano" };
    slbLangages = new SelectBox<String>(skin);
    slbLangages.setItems(lang);

    ///Back Button
    btnBack = new TextButton(language.getString("button_back"), skin);
    btnBack.setName(language.getString("button_back"));

    ///Right Button
    lblRight = new Label(language.getString("label_right"), skin);
    btnRight = new TextButton(game.getRightKey(), skin);
    btnRight.setName("right");

    ///Left Button
    lblLeft = new Label(language.getString("label_left"), skin);
    btnLeft = new TextButton(game.getLeftKey(), skin);
    btnLeft.setName("left");

    ///Down Button
    lblDown = new Label(language.getString("label_down"), skin);
    btnDown = new TextButton(game.getDownKey(), skin);
    btnDown.setName("down");

    ///Up Button
    lblUp = new Label(language.getString("label_up"), skin);
    btnUp = new TextButton(game.getUpKey(), skin);
    btnUp.setName("up");

    ///Zoom In Button
    lblZoomIn = new Label(language.getString("label_zoom_in"), skin);
    btnZoomIn = new TextButton(game.getZoomInKey(), skin);
    btnZoomIn.setName("zoom+");

    ///Zoom Out Button
    lblZoomOut = new Label(language.getString("label_zoom_out"), skin);
    btnZoomOut = new TextButton(game.getZoomOutKey(), skin);
    btnZoomOut.setName("zoom-");

    Gdx.input.setInputProcessor(stage);
}

From source file:awakening.view.menu.Graphics.java

License:Apache License

/**
 * Constructor/*from ww  w .  j  a  v  a2 s  .  c  om*/
 * 
 * @param game Tower Awakening's Game
 * @param sound Main menu's music
 * @param effect Button's effect
 */
public Graphics(TAGame game, Music sound, Sound effect) {
    this.game = game;
    this.sound = sound;
    this.effect = effect;
    stage = new Stage();

    try {
        if (game.getLanguage().equals("ENGLISH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_en_EN", locales[0]);
        } else if (game.getLanguage().equals("FRENCH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_fr_FR", locales[1]);
        } else if (game.getLanguage().equals("ITALIAN")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_it_IT", locales[2]);
        } else {
            language = ResourceBundle.getBundle("awakening.menu.res", locales[0]);
        }
    } catch (java.util.MissingResourceException e) {
        System.out.println("yolo");
    }

    ///Viewport
    camera = new OrthographicCamera();
    view = new StretchViewport(Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getWidth(), camera);

    ///Background
    background = new Texture(Gdx.files.internal("img/menu/Background-3.png"));
    batch = new SpriteBatch();

    ///Skin
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    ///Title
    title = new Label(language.getString("label_graphics_menu"), skin);

    ///Widgets Background
    widgetsBackground = new Image(new Texture(Gdx.files.internal("img/widget/bg widgets.png")));

    ///Back Button
    btnBack = new TextButton(language.getString("button_back"), skin);

    ///CheckBox Fullscreen
    cbxFullscreen = new CheckBox(language.getString("label_fullscreen"), skin);

    ///SelectBox Resolution
    slbResolutions = new SelectBox<TAScreenSize>(skin);

    ///Label Resolution
    lblResolution = new Label(language.getString("label_resolution"), skin);
}

From source file:awakening.view.menu.MainMenu.java

License:Apache License

/**
 * Constructor//from w  ww  . j a  v  a 2 s. c  o  m
 * 
 * @param game Tower Awakening's Game
 */
public MainMenu(TAGame game) {
    super();
    this.game = game;
    this.music = Gdx.audio.newMusic(Gdx.files.internal("sound/menu/Dark Intro_0.ogg"));
    effect = Gdx.audio.newSound(Gdx.files.internal("sound/widget/Button Sound 53.wav"));
    stage = new Stage();

    ///Language
    try {
        if (game.getLanguage().equals("ENGLISH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_en_EN", locales[0]);
        } else if (game.getLanguage().equals("FRENCH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_fr_FR", locales[1]);
        } else if (game.getLanguage().equals("ITALIAN")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_it_IT", locales[2]);
        } else {
            language = ResourceBundle.getBundle("awakening.view.menu.res", locales[0]);
        }
    } catch (java.util.MissingResourceException e) {
        System.out.println("yolo");
    }

    ///Viewport
    camera = new OrthographicCamera();
    view = new StretchViewport(Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getWidth(), camera);

    ///Background
    background = new Texture(Gdx.files.internal("img/menu/background-menu.png"));
    batch = new SpriteBatch();

    ///Skin
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    font = new BitmapFont(Gdx.files.internal("font/space.fnt"));
    style = new LabelStyle(font, Color.WHITE);

    ///Title
    title = new Label(language.getString("label_main_title"), skin);
    title.setStyle(style);

    ///Widgets Background
    widgetsBackground = new Image(new Texture(Gdx.files.internal("img/widget/bg widgets.png")));

    ///Exit Button
    btnExit = new TextButton(language.getString("button_exit"), skin);

    ///Options Button
    btnOptions = new TextButton(language.getString("button_options"), skin);

    ///Multiplayer Button
    btnMultiplayer = new TextButton(language.getString("button_multiplayer"), skin);

    ///Solo Button
    btnSolo = new TextButton(language.getString("button_solo"), skin);

}

From source file:awakening.view.menu.MainMenu.java

License:Apache License

/**
 * Constructor//from   ww  w . j a v  a2 s. c o m
 * 
 * @param game Tower Awakening's Game
 * @param sound Main menu's music
 * @param effect Button's effect
 */
public MainMenu(TAGame game, Music sound, Sound effect) {
    this.game = game;
    this.music = sound;
    this.effect = effect;
    stage = new Stage();

    ///Language
    try {
        if (game.getLanguage().equals("ENGLISH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_en_EN", locales[0]);
        } else if (game.getLanguage().equals("FRENCH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_fr_FR", locales[1]);
        } else if (game.getLanguage().equals("ITALIAN")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_it_IT", locales[2]);
        } else {
            language = ResourceBundle.getBundle("awakening.view.menu.res", locales[0]);
        }
    } catch (java.util.MissingResourceException e) {
        System.out.println("yolo");
    }

    ///Viewport
    camera = new OrthographicCamera();
    view = new StretchViewport(Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getWidth(), camera);

    ///Background
    background = new Texture(Gdx.files.internal("img/menu/background-menu.png"));
    batch = new SpriteBatch();

    ///Skin
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    font = new BitmapFont(Gdx.files.internal("font/space.fnt"));
    style = new LabelStyle(font, Color.WHITE);

    ///Title
    title = new Label(language.getString("label_main_title"), skin);
    title.setStyle(style);

    ///Widgets Background
    widgetsBackground = new Image(new Texture(Gdx.files.internal("img/widget/bg widgets.png")));

    ///Exit Button
    btnExit = new TextButton(language.getString("button_exit"), skin);

    ///Options Button
    btnOptions = new TextButton(language.getString("button_options"), skin);

    ///Multiplayer Button
    btnMultiplayer = new TextButton(language.getString("button_multiplayer"), skin);

    ///Solo Button
    btnSolo = new TextButton(language.getString("button_solo"), skin);
}

From source file:awakening.view.menu.MapSelection.java

License:Apache License

/**
 * Constructor/* ww w .j  a v a2s.c o m*/
 * 
 * @param game Tower Awakening's Game
 * @param sound Main menu's music
 * @param effect Button's effect
 */
public MapSelection(final TAGame game, Music sound, final Sound effect) {
    this.game = game;
    this.sound = sound;
    this.effect = effect;
    stage = new Stage();

    try {
        File monsterDirectory = Gdx.files.internal("Field").file();
        for (File ft : monsterDirectory.listFiles()) {
            if (ft.isFile())
                if (ft.getName().endsWith("mta")) {
                    Field newMap = Field.loadTower(ft);
                    if (newMap != null)
                        mapListes.add(newMap);
                }
        }

        if (game.getLanguage().equals("ENGLISH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_en_EN", locales[0]);
        } else if (game.getLanguage().equals("FRENCH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_fr_FR", locales[1]);
        } else if (game.getLanguage().equals("ITALIAN")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_it_IT", locales[2]);
        } else {
            language = ResourceBundle.getBundle("awakening.view.menu.res", locales[0]);
        }
    } catch (java.util.MissingResourceException e) {
        System.out.println("yolo");
    }

    ///Viewport
    camera = new OrthographicCamera();
    view = new StretchViewport(Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getWidth(), camera);

    ///Background
    background = new Texture(Gdx.files.internal("img/menu/Background-2.png"));
    batch = new SpriteBatch();

    ///Skin
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    ///Title
    title = new Label(language.getString("label_map_selection"), skin);

    ///Widgets Background
    widgetsBackground = new Image(new Texture(Gdx.files.internal("img/widget/window_selection.png")));
    widgetsBackground.setSize(Gdx.app.getGraphics().getWidth() - Gdx.app.getGraphics().getWidth() / 8,
            Gdx.app.getGraphics().getHeight() - Gdx.app.getGraphics().getHeight() / 8);

    ///Back Button
    btnBack = new TextButton(language.getString("button_back"), skin);
    btnJeu = new TextButton(language.getString("button_game"), skin);

    ///Next Button
    Texture t1 = new Texture(Gdx.files.internal("img/widget/arrow_hover_right.png"));
    Texture t2 = new Texture(Gdx.files.internal("img/widget/arrow_right.png"));
    ImageButtonStyle style1 = new ImageButtonStyle(
            new TextureRegionDrawable(new TextureRegion(t1, 0, 0, t1.getWidth(), t1.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t2, 0, 0, t2.getWidth(), t2.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t1, 0, 0, t1.getWidth(), t1.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t2, 0, 0, t2.getWidth(), t2.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t1, 0, 0, t1.getWidth(), t1.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t2, 0, 0, t2.getWidth(), t2.getHeight())));
    btnNext = new ImageButton(style1);

    ///Previous Button
    Texture t3 = new Texture(Gdx.files.internal("img/widget/arrow_hover_left.png"));
    Texture t4 = new Texture(Gdx.files.internal("img/widget/arrow_left.png"));
    ImageButtonStyle style2 = new ImageButtonStyle(
            new TextureRegionDrawable(new TextureRegion(t3, 0, 0, t3.getWidth(), t3.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t4, 0, 0, t4.getWidth(), t4.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t3, 0, 0, t3.getWidth(), t3.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t4, 0, 0, t4.getWidth(), t4.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t3, 0, 0, t3.getWidth(), t3.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t4, 0, 0, t4.getWidth(), t4.getHeight())));

    btnPrevious = new ImageButton(style2);

    maps = new ArrayList<BoutonShop>();

}

From source file:awakening.view.menu.Multiplayer.java

License:Apache License

/**
 * Constructor/*from  w w w .ja v  a  2 s . c  om*/
 * 
 * @param game Tower Awakening's Game
 * @param sound Main menu's music
 * @param effect Button's effect
 */
public Multiplayer(TAGame game, Music sound, Sound effect) {
    this.game = game;
    this.sound = sound;
    this.effect = effect;
    stage = new Stage();

    try {
        if (game.getLanguage().equals("ENGLISH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_en_EN", locales[0]);
        } else if (game.getLanguage().equals("FRENCH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_fr_FR", locales[1]);
        } else if (game.getLanguage().equals("ITALIAN")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_it_IT", locales[2]);
        } else {
            language = ResourceBundle.getBundle("awakening.view.menu.res", locales[0]);
        }
    } catch (java.util.MissingResourceException e) {
        System.out.println("yolo");
    }

    ///Viewport
    camera = new OrthographicCamera();
    view = new StretchViewport(Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getWidth(), camera);

    ///Background
    background = new Texture(Gdx.files.internal("img/menu/Background-2.png"));
    batch = new SpriteBatch();

    ///Skin
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    ///Title
    title = new Label(language.getString("button_multiplayer"), skin);

    ///Widgets Background
    widgetsBackground = new Image(new Texture(Gdx.files.internal("img/widget/window_large.png")));

    ///Back Button
    btnBack = new TextButton(language.getString("button_back"), skin);

    ///Server List
    btnJoin = new TextButton(language.getString("button_join"), skin);
    btnCreate = new TextButton(language.getString("button_create"), skin);

    ///Port TextField
    tfdPort = new TextField("", skin);

    ///Port TextField
    tfdIp = new TextField("", skin);

}