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

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

Introduction

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

Prototype

public Pixmap(byte[] encodedData, int offset, int len) 

Source Link

Document

Creates a new Pixmap instance from the given encoded image data.

Usage

From source file:com.finalproject.MainGame.EndScreen.java

public void create() {
    batch = new SpriteBatch();
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);/*from   w  ww .j  a v a 2 s .  co m*/

    skin = new Skin();
    // Generate a 1x1 white texture and store it in the skin named "black".                
    Pixmap pixmap = new Pixmap(100, 75, Format.RGBA8888);
    pixmap.setColor(Color.BLACK);
    pixmap.fill();

    skin.add("black", new Texture(pixmap));

    BitmapFont bfont = new BitmapFont();
    BitmapFont titleFont = new BitmapFont();
    titleFont.getData().setScale(1);
    bfont.getData().setScale(1);
    skin.add("default", bfont);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("black", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("black", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("black", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("black", Color.LIGHT_GRAY);
    LabelStyle textLabelStyle = new LabelStyle();
    textLabelStyle.font = skin.getFont("default");

    textButtonStyle.font = skin.getFont("default");
    // Import the fonts for the Loose label
    skin.add("default", textButtonStyle);
    skin.add("default", textLabelStyle);

    // Add the end screen label
    final Label title = new Label("  Y o u  L o s e !  ", textLabelStyle);
    title.setPosition(265, 300);
    stage.addActor(title);
}

From source file:com.finalproject.MainGame.MenuScreen.java

public void create() {
    // play the start screen sound
    AssetManager.splash.play();/*w ww . j  a v a2  s  .  c  o m*/
    batch = new SpriteBatch();
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);

    skin = new Skin();
    // Generate a 1x1 white texture and store it in the skin named "black".
    Pixmap pixmap = new Pixmap(100, 75, Format.RGBA8888);
    pixmap.setColor(Color.BLACK);
    pixmap.fill();

    skin.add("black", new Texture(pixmap));

    BitmapFont bfont = new BitmapFont();
    BitmapFont titleFont = new BitmapFont();
    titleFont.getData().setScale(1);
    bfont.getData().setScale(1);
    skin.add("default", bfont);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("black", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("black", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("black", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("black", Color.LIGHT_GRAY);
    LabelStyle textLabelStyle = new LabelStyle();
    textLabelStyle.font = skin.getFont("default");

    textButtonStyle.font = skin.getFont("default");
    // Import the fonts for the start button and the instructions
    skin.add("default", textButtonStyle);
    skin.add("default", textLabelStyle);

    // Add the start button and instructions labels
    final TextButton textButton = new TextButton("Start", textButtonStyle);
    final Label title = new Label("Call of Duty Ghosts - NAWN Edition", textLabelStyle);
    final Label Instructions = new Label(" W, A, S, D keys to move the player around   ", textLabelStyle);
    final Label Instructions2 = new Label(" Left click to shoot   ", textLabelStyle);

    //set the position of the start button and the instructions labels
    title.setPosition(210, 400);
    Instructions.setPosition(190, 150);
    Instructions2.setPosition(280, 100);
    textButton.setPosition(275, 300);

    //import the buttons and labels into the gameScreen
    stage.addActor(title);
    stage.addActor(Instructions);
    stage.addActor(Instructions2);
    stage.addActor(textButton);

    //add a listener to determine when the start button has been Clicked
    textButton.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            //When the start button has been clicked
            // remove the start button
            // start the game
            // turn of the start screen music    
            textButton.remove();
            g.setScreen(new MainGame(g));
            AssetManager.splash.dispose();
        }
    });
}

From source file:com.finalproject.MainGame.WinScreen.java

public void create() {
    batch = new SpriteBatch();
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);//from www  .  j  av  a  2 s  .  c  om

    skin = new Skin();
    // Generate a 1x1 white texture and store it in the skin named "black".
    Pixmap pixmap = new Pixmap(100, 75, Format.RGBA8888);
    pixmap.setColor(Color.BLACK);
    pixmap.fill();

    skin.add("black", new Texture(pixmap));

    BitmapFont bfont = new BitmapFont();
    BitmapFont titleFont = new BitmapFont();
    titleFont.getData().setScale(1);
    bfont.getData().setScale(1);
    skin.add("default", bfont);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("black", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("black", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("black", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("black", Color.LIGHT_GRAY);
    LabelStyle textLabelStyle = new LabelStyle();
    textLabelStyle.font = skin.getFont("default");

    textButtonStyle.font = skin.getFont("default");
    // Import the fonts for the Win label
    skin.add("default", textButtonStyle);
    skin.add("default", textLabelStyle);
    // Add the Win screen Label
    final Label title = new Label("  Y o u  W i n!  ", textLabelStyle);
    title.setPosition(265, 300);
    stage.addActor(title);
}

From source file:com.gamejolt.mikykr5.ceidecpong.GameCore.java

License:Open Source License

@Override
public void create() {
    AsyncAssetLoader loader = AsyncAssetLoader.getInstance();

    // Set up rendering fields and settings.
    ShaderProgram.pedantic = false; // Not passing all variables to a shader will not close the game.
    batch = new SpriteBatch();
    batch.enableBlending();/*ww  w  .j av a 2  s.c  o m*/
    batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    // Prepare the fading effect.
    Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444);
    pixmap.setColor(0, 0, 0, 1);
    pixmap.fill();
    fadeTexture = new Texture(pixmap);
    pixmap.dispose();

    // Create the initial interpolators and start with a fade in effect.
    alpha = new MutableFloat(1.0f);
    fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint);
    fadeIn = Tween.to(alpha, 0, 2.5f).target(0.0f).ease(TweenEquations.easeInQuint);
    fadeIn.start();
    fading = true;

    // Create application states.
    states = new BaseState[game_states_t.getNumStates()];

    try {
        states[game_states_t.LOGO_SCREEN.getValue()] = new LogoScreenState(this);
        states[game_states_t.MAIN_MENU.getValue()] = new MainMenuState(this);
        states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
        states[game_states_t.LOADING.getValue()] = new LoadingState(this);
        states[game_states_t.QUIT.getValue()] = null;
    } catch (IllegalArgumentException e) {
        Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument caught creating states: ", e);
        System.exit(1);
        return;
    }

    // Register every state as an AssetsLoadedListener if the state implements the interface.
    for (BaseState state : states) {
        if (state != null && state instanceof AssetsLoadedListener)
            loader.addListener((AssetsLoadedListener) state);
    }
    AsyncAssetLoader.freeInstance();
    loader = null;

    // Set the initial current and next states.
    currState = game_states_t.LOGO_SCREEN;
    nextState = null;
    this.setScreen(states[currState.getValue()]);

    // Set log level
    if (ProjectConstants.DEBUG) {
        Gdx.app.setLogLevel(Application.LOG_DEBUG);
    } else {
        Gdx.app.setLogLevel(Application.LOG_NONE);
    }
}

From source file:com.gdx.extension.ui.color.SlideColorPicker.java

License:Apache License

/**
 * Generate the slider background./*from  w ww  .jav a  2 s  .co m*/
 */
public void initialize() {
    pixMap = new Pixmap((int) getWidth(), (int) getHeight(), Format.RGBA8888);
    int _colorMin = (int) colorRange.x;
    int _colorMax = (int) colorRange.y;
    int _colorCount = (_colorMax - _colorMin);
    float _scaleRatio = (float) _colorCount / ((isVertical) ? pixMap.getHeight() : pixMap.getWidth());

    for (int i = 0; i <= (isVertical ? pixMap.getHeight() : pixMap.getWidth()); i++) {
        Color _color = ColorUtil.getHSBColor((i * _scaleRatio + _colorMin) / ((float) _colorMax), saturation,
                brightness);

        pixMap.setColor(_color.getRed() / 256f, _color.getGreen() / 256f, _color.getBlue() / 256f,
                _color.getAlpha() / 256f);
        if (isVertical)
            pixMap.drawLine(0, i, pixMap.getWidth(), i);
        else
            pixMap.drawLine(i, 0, i, pixMap.getHeight());
    }

    TextureRegionDrawable _background = new TextureRegionDrawable(new TextureRegion(new Texture(pixMap)));
    if (isVertical)
        _background.getRegion().flip(false, true);
    getStyle().background = _background;
    setStyle(getStyle());
    pixMap.dispose();
}

From source file:com.gdx.extension.ui.color.SwatchesColorPicker.java

License:Apache License

/**
 * Initialize the color picker by adding items.
 *//* w ww  . ja v a2s.c  om*/
protected void initialize() {
    for (Color _color : preset.getColors()) {
        Pixmap _pixMap = new Pixmap((int) getItemWidth(), (int) getItemHeight(), Format.RGBA8888);
        _pixMap.setColor(_color);
        _pixMap.fill();
        SwatchesColorPickerGridItem _item = new SwatchesColorPickerGridItem(style,
                new Image(new Texture(_pixMap)), _color);
        _pixMap.dispose();
        addItem(_item);
    }
}

From source file:com.github.skittishSloth.openSkies.maps.MapGenerator.java

public Texture generateTexture(final int width, final int height, final int tileSize) {
    final TerrainTile[][] tiles = generateTiles(width, height);

    final Pixmap pm = new Pixmap(width * tileSize, height * tileSize, Pixmap.Format.RGBA8888);
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            final TerrainTile tile = tiles[x][y];
            final Color c = tile.getTemperatureColor();
            pm.setColor(c);/*from  w w w .j  a va  2 s.  c  o m*/
            pm.fillRectangle(x * tileSize, y * tileSize, tileSize, tileSize);
        }
    }
    final Texture res = new Texture(pm);
    pm.dispose();
    return res;
}

From source file:com.github.skittishSloth.openSkies.maps.MapGenerator.java

public Texture generateElevationTexture(final TerrainTile[][] tiles, final int width, final int height,
        final int tileSize) {
    final Pixmap pm = new Pixmap(width * tileSize, height * tileSize, Pixmap.Format.RGBA8888);
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            final TerrainTile tile = tiles[x][y];
            final Color c = tile.getElevationColor();
            pm.setColor(c);/*from  w  ww  . ja va 2s  .  com*/
            pm.fillRectangle(x * tileSize, y * tileSize, tileSize, tileSize);
        }
    }
    final Texture res = new Texture(pm);
    pm.dispose();
    return res;
}

From source file:com.github.skittishSloth.openSkies.maps.MapGenerator.java

public Texture generateRawElevationTexture(final TerrainTile[][] tiles, final int width, final int height,
        final int tileSize) {
    final Pixmap pm = new Pixmap(width * tileSize, height * tileSize, Pixmap.Format.RGBA8888);
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            final TerrainTile tile = tiles[x][y];
            final Color c = tile.getRawElevationColor();
            pm.setColor(c);/*from   ww  w  .ja  va  2  s. c  o m*/
            pm.fillRectangle(x * tileSize, y * tileSize, tileSize, tileSize);
        }
    }
    final Texture res = new Texture(pm);
    pm.dispose();
    return res;
}

From source file:com.github.skittishSloth.openSkies.maps.MapGenerator.java

public Texture generateTemperatureTexture(final TerrainTile[][] tiles, final int width, final int height,
        final int tileSize) {
    final Pixmap pm = new Pixmap(width * tileSize, height * tileSize, Pixmap.Format.RGBA8888);
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            final TerrainTile tile = tiles[x][y];
            final Color c = tile.getTemperatureColor();
            pm.setColor(c);/* w  w  w  .  ja  va2s . c om*/
            pm.fillRectangle(x * tileSize, y * tileSize, tileSize, tileSize);
        }
    }
    final Texture res = new Texture(pm);
    pm.dispose();
    return res;
}