Example usage for com.badlogic.gdx.graphics.g2d SpriteBatch enableBlending

List of usage examples for com.badlogic.gdx.graphics.g2d SpriteBatch enableBlending

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d SpriteBatch enableBlending.

Prototype

@Override
    public void enableBlending() 

Source Link

Usage

From source file:com.bladecoder.engine.model.Scene.java

License:Apache License

public void draw(SpriteBatch batch) {

    if (background != null) {
        batch.disableBlending();//  w w w .j a v  a2 s.  c om
        batch.setProjectionMatrix(camera.calculateParallaxMatrix(1, 1));
        batch.begin();

        float x = 0;

        for (AtlasRegion tile : background) {
            batch.draw(tile, x, 0f);
            x += tile.getRegionWidth();
        }

        batch.end();
        batch.enableBlending();
    }

    // draw layers from bottom to top
    for (int i = layers.size() - 1; i >= 0; i--) {
        SceneLayer layer = layers.get(i);

        batch.setProjectionMatrix(camera.calculateParallaxMatrix(layer.getParallaxMultiplier(), 1));
        batch.begin();
        layer.draw(batch);
        batch.end();
    }
}

From source file:com.longarmx.color.Component.java

License:Apache License

/**
 * //from w ww.  j a  v a  2  s  .  c o m
 * @param batch   The current, active SpriteBatch
 */
public void render(SpriteBatch batch) {
    batch.enableBlending();
    batch.draw(texture, x, y, width, height);
}

From source file:com.longarmx.color.Enemy.java

License:Apache License

public void render(SpriteBatch batch) {
    batch.enableBlending();
    batch.setColor(0, 0, 0, 1);//from   ww  w.j av  a2s  .c  o  m
    batch.draw(textureTop, x + 1, yTop, 0, 0, 50, 25, 1, 1, -rotation);
    batch.draw(textureBottom, x + 1, yBottom, 0, 0, 50, 25, 1, 1, rotation);
    batch.setColor(red, green, blue, 1);
    batch.draw(textureTop, x, yTop, 0, 0, 50, 25, 1, 1, -rotation);
    batch.draw(textureBottom, x, yBottom, 0, 0, 50, 25, 1, 1, rotation);
    batch.setColor(1, 1, 1, 1);
}

From source file:com.longarmx.color.FontManager.java

License:Apache License

public void draw(String string, int x, int y, float scale, SpriteBatch batch) {
    batch.enableBlending();
    batch.setColor(r, g, b, a);/*from w w w. j  a va  2s. co m*/
    string = string.toUpperCase();
    char[] chars = string.toCharArray();
    int x1 = 0;
    for (int i = 0; i < chars.length; i++) {
        batch.draw(charactersRegion[getCharI(chars[i])], x + x1 * charWidth * scale * spacing, y,
                scale * charWidth, scale * charHeight);
        x1++;
    }
}

From source file:com.longarmx.color.Player.java

License:Apache License

/**
 *  Where the rendering happens.//from w w w  .j a  v  a2s.  co  m
 *  @param batch The active Spritebatch. Must be drawing.
 */
public void render(SpriteBatch batch) {
    update();
    batch.enableBlending();
    batch.setColor(0, 0, 0, 1);
    batch.draw(player, x + 1, y, width, height);
    batch.setColor(new Color(red, green, blue, 1));
    if (isShooting) {
        makeLightning(batch);
        batch.draw(lightning, x + width, y + height / 2, 0, 0, 1, 1, Main.ORIGINAL_WIDTH - x, 3, 0);
    }
    batch.draw(player, x, y, width, height);
    batch.setColor(1, 1, 1, 1);
}

From source file:com.mob.dao.objects.Map.java

License:Open Source License

/**
 * Renders a map layer to it's internal FrameBuffer Object
 *
 * @param layer//www. j  a  v a 2 s .com
 * @return void
 */
public void renderLayerToBuffer(int layer) {

    int width = (int) (Map.MAX_MAP_SIZE_WIDTH * Map.TILE_PIXEL_WIDTH);
    int height = (int) (Map.MAX_MAP_SIZE_HEIGHT * Map.TILE_PIXEL_HEIGHT);

    OrthographicCamera camera = new OrthographicCamera(width, height);
    camera.setToOrtho(true, width, height);

    FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
    SpriteBatch sb = new SpriteBatch();
    sb.setProjectionMatrix(camera.combined);
    fbo.begin();

    sb.enableBlending();
    Gdx.gl.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE,
            GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.gl.glViewport(0, 0, width, height);
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    sb.begin();
    this.renderLayer(sb, layer);
    sb.end();

    fbo.end();
    this.bufferedLayer = fbo.getColorBufferTexture();
}

From source file:org.bladecoder.bladeengine.model.Scene.java

License:Apache License

public void draw(SpriteBatch spriteBatch) {

    if (background != null) {
        spriteBatch.disableBlending();/*from w ww  .ja  va2s . c  om*/

        float x = 0;

        for (Texture tile : background) {
            spriteBatch.draw(tile, x, 0f);
            x += tile.getWidth();
        }

        spriteBatch.enableBlending();
    }

    for (Actor a : orderedActors) {
        if (a instanceof SpriteActor)
            ((SpriteActor) a).draw(spriteBatch);
    }

    for (SpriteActor a : fgActors) {
        a.draw(spriteBatch);
    }

    // Draw the light map
    if (lightMap != null) {
        // Multiplicative blending for light maps
        spriteBatch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ZERO);

        float x = 0;

        for (Texture tile : lightMap) {
            spriteBatch.draw(tile, x, 0f);
            x += tile.getWidth();
        }

        spriteBatch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }

    if (overlay != null) {
        overlay.draw(spriteBatch);
    }

    if (EngineLogger.debugMode() && EngineLogger.getDebugLevel() == EngineLogger.DEBUG1) {

        StringBuilder sb = new StringBuilder();

        for (Actor a : orderedActors) {
            Rectangle r = a.getBBox().getBoundingRectangle();
            sb.setLength(0);
            sb.append(a.getId());
            if (a.getState() != null)
                sb.append(".").append(a.getState());
            // sb.append(" (").append((int) r.getX()).append(", ");
            // sb.append((int) r.getY()).append(", ").append((int)
            // r.getWidth());
            // sb.append(", ").append((int) r.getHeight()).append(") ");
            EngineLogger.getDebugFont().draw(spriteBatch, sb.toString(), r.getX(), r.getY());
        }

    }
}

From source file:org.matheusdev.ror.screens.ScreenGameMap.java

License:Open Source License

@Override
public void draw(SpriteBatch batch) {
    if (bloom != Config.get().bloom) {
        processor = rebuildProcessor();//from w  w w  .j a  v  a2  s.  c om
    }
    processor.capture();

    cam.loadToBatch(batch);

    map.renderBelowEntities(cam.getCam());

    batch.enableBlending();
    batch.begin();
    client.draw(batch, map.getFringeLayer(), Gdx.graphics.getDeltaTime());
    batch.end();

    map.renderAboveEntities(cam.getCam());

    processor.render();

    if (debugDraw)
        debugRenderer.render(client.getPhysics().getWorld(), cam.getCam().combined);

    drawHUD(batch);
}