Search in sources :

Example 71 with Texture

use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.

the class SuperKoalio method create.

@Override
public void create() {
    // load the koala frames, split them, and assign them to Animations
    koalaTexture = new Texture("data/maps/tiled/super-koalio/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("data/maps/tiled/super-koalio/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);
    camera.update();
    // create the Koala we want to move around the world
    koala = new Koala();
    koala.position.set(20, 20);
    debugRenderer = new ShapeRenderer();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) Animation(com.badlogic.gdx.graphics.g2d.Animation) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Texture(com.badlogic.gdx.graphics.Texture) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 72 with Texture

use of com.badlogic.gdx.graphics.Texture in project netthreads-libgdx by alistairrutherford.

the class TextureCache method load.

/**
	 * Load predefined textures.
	 * 
	 * This requires texture definitions to be added to the {@link AppActorTextures} structure.
	 */
public void load(List<TextureDefinition> textureDefinitions) {
    if (textureAtlas == null) {
        textureAtlas = new TextureAtlas();
    } else {
        dispose();
        textureAtlas = new TextureAtlas();
    }
    for (TextureDefinition definition : textureDefinitions) {
        Texture texture = new Texture(Gdx.files.internal(definition.getPath()));
        TextureRegion textureRegion = new TextureRegion(texture);
        textureAtlas.addRegion(definition.getName(), textureRegion);
        definitions.put(definition.getName(), definition);
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Texture(com.badlogic.gdx.graphics.Texture)

Example 73 with Texture

use of com.badlogic.gdx.graphics.Texture in project AnotherMonekyParadox by SantiagoMille.

the class PantallaJuego method crearMapa.

private void crearMapa() {
    cargarTexturas();
    stageNivel = new Stage(vista);
    // Objeto que dibuja texto
    texto = new Texto(1, 1, 1);
    for (int i = 0; i < 3; i++) {
        if (i < 3) {
            vidas.add(new PowerUp(new Texture("vida.png"), camara.position.x + 10 - ANCHO / 2 + (75 * i), ALTO - 70, true));
        } else {
            vidas.add(new PowerUp(new Texture("vida.png"), camara.position.x + 10 - ANCHO / 2 + (75 * i), ALTO - 70, false));
        }
    }
    // Boton granadas
    TextureRegionDrawable btnGranada = new TextureRegionDrawable(new TextureRegion(botonGranada));
    granada = new ImageButton(btnGranada);
    granada.setSize(135, 135);
    granada.setPosition(ANCHO * 3 / 4 - granada.getWidth() / 2 + 25, ALTO / 4 - granada.getHeight() / 2 - 80);
    // boton disparo
    TextureRegionDrawable btnArma = new TextureRegionDrawable(new TextureRegion(botonDisparo));
    arma = new ImageButton(btnArma);
    arma.setSize(135, 135);
    arma.setPosition(ANCHO * 3 / 4 - arma.getWidth() / 2 + arma.getWidth() + 55, ALTO / 4 - arma.getHeight() / 2 - 80);
    // boton pausa
    TextureRegionDrawable btnPausa = new TextureRegionDrawable(new TextureRegion(botonPausa));
    pausa = new ImageButton(btnPausa);
    pausa.setSize(55, 55);
    pausa.setPosition(ANCHO / 2 - pausa.getWidth() / 2, 680 - pausa.getHeight() / 2);
    // boton continua
    TextureRegionDrawable btnContinua = new TextureRegionDrawable(new TextureRegion(botonContinua));
    continua = new ImageButton(btnContinua);
    continua.setSize(55, 55);
    continua.setPosition(ANCHO / 2 - continua.getWidth() / 2, 680 - continua.getHeight() / 2);
    // boton Home
    TextureRegionDrawable btnHome = new TextureRegionDrawable(new TextureRegion(botonHome));
    home = new ImageButton(btnContinua);
    home.setSize(55, 55);
    home.setPosition(ANCHO / 2 - continua.getWidth() / 2, 680 - continua.getHeight() / 2);
    // Texturas para el pad
    Skin skin = new Skin();
    skin.add("fondo", padBack);
    skin.add("boton", padKnob);
    Touchpad.TouchpadStyle estilo = new Touchpad.TouchpadStyle();
    estilo.background = skin.getDrawable("fondo");
    estilo.knob = skin.getDrawable("boton");
    // Crea el pad
    // Radio, estilo
    Touchpad pad = new Touchpad(64, estilo);
    // x,y - ancho,alto
    pad.setBounds(20, 20, 160, 160);
    // Comportamiento del pad
    pad.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            Touchpad pad = (Touchpad) actor;
            if (pad.getKnobPercentX() > 0.10) {
                // Más de 20% de desplazamiento DERECHA
                // personaje.setX(personaje.getX()+3);
                personaje.setRight(true);
                isMovingRight = true;
                isMovingLeft = false;
            } else if (pad.getKnobPercentX() < -0.10) {
                // Más de 20% IZQUIERDA
                // personaje.setX(personaje.getX()-3);
                personaje.setRight(false);
                isMovingLeft = true;
                isMovingRight = false;
            } else {
                isMovingLeft = false;
                isMovingRight = false;
            }
        }
    });
    // Transparente
    pad.setColor(1, 1, 1, 0.7f);
    // Comportamiento de Boton Granada
    granada.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            if (!isFliped) {
                Granada grana = new Granada(bananaGranada, false);
                grana.set(personaje.getX() + 105, personaje.getY() + 68);
                listaGranadas.add(grana);
            } else {
                Granada grana = new Granada(bananaGranada, true);
                grana.set(personaje.getX(), personaje.getY() + 68);
                listaGranadas.add(grana);
            }
        }
    });
    // Comportamiento de Boton Disparo
    arma.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            gunSound.play();
            if (!isFliped) {
                Bala nueva = new Bala(bananaDisparo, false);
                nueva.set(personaje.getX() + 105, personaje.getY() + 68);
                listaBalas.add(nueva);
            } else {
                Bala nueva = new Bala(bananaDisparo, true);
                nueva.set(personaje.getX(), personaje.getY() + 68);
                listaBalas.add(nueva);
            }
        }
    });
    // Comportamiento de Boton Pausa
    pausa.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            estado = EstadoJuego.PAUSADO;
            // main.setScreen((Screen) new EscenaPausa(vista,batch));
            if (escenaPausa == null) {
                escenaPausa = new EscenaPausa(vista, batch);
            }
            Gdx.input.setInputProcessor(escenaPausa);
            dispose();
        }
    });
    stageNivel.addActor(granada);
    stageNivel.addActor(arma);
    stageNivel.addActor(pausa);
    stageNivel.addActor(pad);
    Gdx.input.setInputProcessor(stageNivel);
}
Also used : TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 74 with Texture

use of com.badlogic.gdx.graphics.Texture in project AnotherMonekyParadox by SantiagoMille.

the class PantallaMenu method crearMenu.

private void crearMenu() {
    cargarTexturas();
    stageMenu = new Stage(vista);
    spriteBackground = new Sprite(backgroundStory);
    spriteBackground.setPosition(0, 0);
    spriteLogo = new Sprite(imgLogo);
    spriteLogo.setPosition(ANCHO / 2 - spriteLogo.getWidth() / 2, ALTO - spriteLogo.getHeight() - 40);
    // Boton Play
    TextureRegionDrawable trdPlay = new TextureRegionDrawable(new TextureRegion(botonPlay));
    TextureRegionDrawable trdPlayPressed = new TextureRegionDrawable(new TextureRegion(botonPlayPressed));
    ImageButton btnPlay = new ImageButton(trdPlay, trdPlayPressed);
    btnPlay.setPosition(ANCHO / 2 - btnPlay.getWidth() / 2, ALTO / 4 - btnPlay.getHeight() / 2);
    // Boton Leaderboard
    TextureRegionDrawable trdLead = new TextureRegionDrawable(new TextureRegion(botonLeaderboard));
    TextureRegionDrawable trdLeadPush = new TextureRegionDrawable(new TextureRegion(botonLeaderboardPressed));
    ImageButton btnLead = new ImageButton(trdLead, trdLeadPush);
    btnLead.setPosition(ANCHO / 4 - btnLead.getWidth() / 2, ALTO / 4 - btnLead.getHeight() / 2);
    // Boton about
    TextureRegionDrawable trdConfig = new TextureRegionDrawable(new TextureRegion(botonAbout));
    TextureRegionDrawable trdConfigPush = new TextureRegionDrawable(new TextureRegion(botonAboutPressed));
    ImageButton btnConfig = new ImageButton(trdConfig, trdConfigPush);
    btnConfig.setPosition(ANCHO * 3 / 4 - btnConfig.getWidth() / 2, ALTO / 4 - btnConfig.getHeight() / 2);
    // Boton Tutorial
    TextureRegionDrawable trdTut = new TextureRegionDrawable(new TextureRegion(botonTutorial));
    TextureRegionDrawable trdTutPush = new TextureRegionDrawable(new TextureRegion(botonTutorialPressed));
    ImageButton btnTut = new ImageButton(trdTut, trdTutPush);
    btnTut.setPosition(ANCHO * 13 / 14, ALTO * 13 / 14 - btnTut.getHeight() / 2);
    // Boton modo horda
    TextureRegionDrawable trdHorda = new TextureRegionDrawable(new TextureRegion(new Texture("arrow-point-to-right.png")));
    btnHorda = new ImageButton(trdHorda);
    btnHorda.setSize(60, 60);
    btnHorda.setPosition(ANCHO - btnHorda.getWidth() - 50, ALTO / 2 - btnHorda.getHeight() / 2 - 10);
    // Boton regresar de modo horda
    TextureRegionDrawable trdRegresarHorda = new TextureRegionDrawable(new TextureRegion(new Texture("arrow-point-to-left.png")));
    btnRegresarHorda = new ImageButton(trdRegresarHorda);
    btnRegresarHorda.setSize(60, 60);
    btnRegresarHorda.setVisible(false);
    btnRegresarHorda.setPosition(50, ALTO / 2 - btnRegresarHorda.getHeight() / 2 - 10);
    // Click en boton Play
    btnPlay.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            dispose();
            main.setScreen(new PantallaCargandoStoryMode(main));
        }
    });
    // Click en boton Lead
    btnLead.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            dispose();
            if (isSurvivalMode) {
                main.setScreen(new PantallaScoresSurvival(main));
            } else {
                main.setScreen(new PantallaScoresStory(main));
            }
        }
    });
    // Click en boton Developer
    btnTut.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            dispose();
            main.setScreen(new PantallaDeveloper(main));
        }
    });
    // Click en boton Horda
    btnHorda.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            isSurvivalMode = true;
            spriteBackground = new Sprite(backgroundSurvival);
            spriteBackground.setPosition(0, 0);
            btnHorda.setVisible(false);
            btnRegresarHorda.setVisible(true);
        }
    });
    // Click para regresar al modo historia
    btnRegresarHorda.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            isSurvivalMode = false;
            spriteBackground = new Sprite(backgroundStory);
            spriteBackground.setPosition(0, 0);
            btnRegresarHorda.setVisible(false);
            btnHorda.setVisible(true);
        }
    });
    // Click en boton Tutorial
    btnConfig.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            dispose();
            if (isSurvivalMode) {
                main.setScreen(new PantallaTutorialSurvivalMode(main));
            } else {
                main.setScreen(new PantallaTutorialStoryMode(main));
            }
        }
    });
    stageMenu.addActor(btnPlay);
    stageMenu.addActor(btnLead);
    stageMenu.addActor(btnConfig);
    stageMenu.addActor(btnTut);
    stageMenu.addActor(btnHorda);
    stageMenu.addActor(btnRegresarHorda);
    inputMultiplexer.addProcessor(stageMenu);
// Gdx.input.setInputProcessor(stageMenu);
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Stage(com.badlogic.gdx.scenes.scene2d.Stage) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 75 with Texture

use of com.badlogic.gdx.graphics.Texture in project AnotherMonekyParadox by SantiagoMille.

the class PantallaScoresStory method crearMenu.

@Override
void crearMenu() {
    super.stageMenu = new Stage(vista);
    title = new Texto(1, 1, 1);
    imgBackground = new Texture("logros.png");
    spriteBackground = new Sprite(imgBackground);
    spriteBackground.setPosition(0, 0);
    // spriteBackground.setAlpha(0.7f);
    Skin skin = new Skin(Gdx.files.internal("skin/comic-ui.json"));
    Preferences prefs = Gdx.app.getPreferences("AnotherMonkeyPreferenceStory");
    String names = prefs.getString("names", null);
    if (names == null) {
        // prefs.putString("names", "Astro");
        names = "Astro,";
    }
    String scores = prefs.getString("highscores", null);
    if (scores == null) {
        // prefs.putString("highscores", "10000");
        scores = "10000,";
    }
    Table table = new Table(skin);
    table.defaults().pad(10f);
    table.setFillParent(true);
    table.setPosition(table.getX(), table.getY() + 250);
    /**
     * Se hace el titulo de scores
     */
    // Label scoresTitle = new Label("HIGHSCORES STORY MODE", skin);
    // scoresTitle.setFontScale(4f,4f);
    // scoresTitle.setAlignment(Align.center);
    /**
     * Se crean las columnas con puntuajes
     */
    Label columnName;
    Label columnScore;
    String[] allScores = scores.split(",");
    String[] allNames = names.split(",");
    int i = 0;
    // table.add(scoresTitle).colspan(2).fillX().height(150);
    table.row();
    for (String name : allNames) {
        columnName = new Label(name + ": ", skin);
        columnName.setFontScale(3f, 3f);
        table.add(columnName);
        columnScore = new Label(allScores[i], skin);
        columnScore.setFontScale(3f, 3f);
        table.add(columnScore);
        i++;
        table.row();
    }
    // Boton Return
    TextureRegionDrawable trdReturn = new TextureRegionDrawable(new TextureRegion(new Texture("go-back.png")));
    ImageButton btnReturn = new ImageButton(trdReturn);
    btnReturn.setPosition(30, ALTO - 30 - btnReturn.getHeight());
    // Click en boton Return
    btnReturn.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            main.setScreen(new PantallaMenu(main));
        }
    });
    stageMenu.addActor(table);
    stageMenu.addActor(btnReturn);
    Gdx.input.setInputProcessor(stageMenu);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Preferences(com.badlogic.gdx.Preferences) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Texture (com.badlogic.gdx.graphics.Texture)235 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)78 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)62 Pixmap (com.badlogic.gdx.graphics.Pixmap)56 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)35 Stage (com.badlogic.gdx.scenes.scene2d.Stage)35 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)26 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)21 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)20 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)19 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)17 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)16 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)16 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)16 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)14 Material (com.badlogic.gdx.graphics.g3d.Material)12 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)12 Actor (com.badlogic.gdx.scenes.scene2d.Actor)11 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)11 FileHandle (com.badlogic.gdx.files.FileHandle)10